To cut right to the chase, I have these two snippets of Lua code. One of which generates three buttons to put in a menu window:
for i=1,3,1 do
local button = Button:new()
button.minHeight = 24
button.name = i
local buttonText = Text:new()
buttonText.text = "Stage "..i
buttonText:SetAlignment(HA_CENTER, VA_CENTER)
window:AddChild(button)
button:SetStyleAuto()
button:AddChild(buttonText)
buttonText:SetStyleAuto()
SubscribeToEvent(button, "Released", "LoadStage")
end
and later on I have that event:
function LoadStage(object, eventType, eventData)
log:Write(LOG_INFO, "Loaded stage "..object.name)
end
In theory, this should result in the log mentioning “Loaded stage 1”, “Loaded stage 2” and “Loaded stage 3” when I press the appropiate button. However, it doesn’t work properly and pressing the buttons results in an “Execute Lua function failed: [string “init”]:61: attempt to concatenate field ‘name’ (a nil value)” error in the log. Any help?