Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
button optional data - Gideros Forum

button optional data

MoKaLuxMoKaLux Member
edited August 31 in General questions
how are you doing?
A question please. I am using the button class in a Sprite class. Can I pass extra data to my button?
btn01:addEventListener("click", self.changeScene, data)
btn01:addEventListener("click", self.changeScene, self, data)

Basically I want to avoid doing this for all my buttons:
btn02:addEventListener("click", function()
	sceneManager:changeScene("levels", 1, transitions[13], easings[7])
Thank you :)
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories


  • hgy29hgy29 Maintainer
    Accepted Answer
    You can assign your custom data to the button itself, and fetch the clicked button from the event.
    btn01.data={ ... }
    function Class:changeScene(evt)
     local data=evt:getTarget().data
  • Thank you hgy29, as we say in french "oui mais non" :)
    This is a way of doing it but it adds another variable to the code.

    I was hoping to get something like:

    An example in the wiki could be useful.

    I'll see if I can figure out something.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • keszeghkeszegh Member
    Accepted Answer
    yes, i also had cases when i wanted to send multiple data for an event and maybe even we had discussions on the forum about it but as far as i can remember there was no perfect solution.

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    Yes, I know, the best way to do it I can think of would be to change Gideros code so that
    would become
    and add the necessary
    before calling the handler

    Likes: keszegh, MoKaLux

    +1 -1 (+2 / -0 ) Share on Facebook
  • MoKaLuxMoKaLux Member
    edited August 31
    one last thing please :)
    do you have a very basic example for data?

    for the wiki: https://wiki.giderosmobile.com/index.php/EventDispatcher:addEventListener
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.