Nope, you have to use if-else-elseif statements. See this for further explanation: http://lua-users.org/wiki/SwitchStatement [import]uid: 8782 topic_id: 6328 reply_id: 21855[/import]
My updated “buttonHandler” function with the new “switch” function:
[lua]buttonHandler = function ( event )
if event.phase == “release” then
switch ( event.id ) : caseof {
[“play”] =
function() – must put “function()” and “end,” to separate
director:changeScene( “levelselect”, “fade” )
end,
[“instr”] =
function()
director:changeScene( “instructions”, “fade” )
end,
[“cred”] =
function()
director:changeScene( “credits”, “fade” )
end,
default = – “default” and “missing” must be added
function()
print( “Button is undefined (default)!” )
end,
missing =
function()
print( “Button is undefined (missing)!” )
end,
}
end
end[/lua] [import]uid: 6084 topic_id: 6328 reply_id: 21968[/import]
it also says most of them trash the garbage collector because of function closures. check it’s not affecting your memory badly [import]uid: 6645 topic_id: 6328 reply_id: 22100[/import]