Can someone tell me what this code does. It might not be enough of information i give but I am making an app with buttons. So i just need someone who can tell me what this code does.
local phase = event.phase
local id = event.target.id
Can someone tell me what this code does. It might not be enough of information i give but I am making an app with buttons. So i just need someone who can tell me what this code does.
local phase = event.phase
local id = event.target.id
I’ll go…
local
Declares a variable as visible to all the code within either the current module or the current function, if statement or loop.
phase id
These are variables which store values you can use later. In this case, phase will be a string (text) which indicates the event’s phase of processing. Here, it has the possible values “began”, “moved”, “ended” or “cancelled”.
event.phase
Touch and Tap events provide information about their current status (or “state”) in a variable which is passed into the function you are no doubt looking at. ‘event’ is the variable in this case. Here, ‘.phase’ is another variable which is contained within the ‘event’ variable. ‘event’ is a Lua table and tables are simply a means of storing information in the Lua language. They behave like lists, dictionaries or collections.
event.target.id
Again we are getting a variable from inside the ‘event’ table, in this case called ‘target’. The target in question is the object which fired the Tap or Touch event, in your case the button the listener was attached to using the statement ‘addEventListener( … )’. The ‘target’ variable is actually the button display object, and so the ‘.id’ is the variable called ‘id’ that the button was given when it was created.
local phase = event.phase
So here we have declared the variable ‘phase’ and assigned it the value from the touch or tap event’s data. You now have a variable which directly states the current phase of the event. The ‘phase’ variable is declared local, so it will only be usable within the function you are looking at.
local id = event.target.id
As with ‘phase’ this ‘id’ is also only available in the current function. It will store the ID of the button object which was touched or tapped.
Thank you thank you and thank you
Excellent explanation Horace! I could have made it clearer myself!
I’ll go…
local
Declares a variable as visible to all the code within either the current module or the current function, if statement or loop.
phase id
These are variables which store values you can use later. In this case, phase will be a string (text) which indicates the event’s phase of processing. Here, it has the possible values “began”, “moved”, “ended” or “cancelled”.
event.phase
Touch and Tap events provide information about their current status (or “state”) in a variable which is passed into the function you are no doubt looking at. ‘event’ is the variable in this case. Here, ‘.phase’ is another variable which is contained within the ‘event’ variable. ‘event’ is a Lua table and tables are simply a means of storing information in the Lua language. They behave like lists, dictionaries or collections.
event.target.id
Again we are getting a variable from inside the ‘event’ table, in this case called ‘target’. The target in question is the object which fired the Tap or Touch event, in your case the button the listener was attached to using the statement ‘addEventListener( … )’. The ‘target’ variable is actually the button display object, and so the ‘.id’ is the variable called ‘id’ that the button was given when it was created.
local phase = event.phase
So here we have declared the variable ‘phase’ and assigned it the value from the touch or tap event’s data. You now have a variable which directly states the current phase of the event. The ‘phase’ variable is declared local, so it will only be usable within the function you are looking at.
local id = event.target.id
As with ‘phase’ this ‘id’ is also only available in the current function. It will store the ID of the button object which was touched or tapped.
Thank you thank you and thank you
Excellent explanation Horace! I could have made it clearer myself!