mtburdon Posted April 15, 2014 Share Posted April 15, 2014 Hi there, I'm trying to do something which I think should be rather simple but I don't seem to be able to achieve it. When a button is clicked, I'm trying to pass a parameter to the button callback function, however if I pass anything to the function and console.log it out, it's always the clicked button. Is there a way to pass a parameter other than the button to the button callback? Thanks!Martin Link to comment Share on other sites More sharing options...
blackgames Posted April 15, 2014 Share Posted April 15, 2014 Hi, the second parameter is as you wrote the button itself. I dont know if this helps you, but you could give the button for example a name (ie Button.name = variable) and read this again in your functionHope it helps mtburdon 1 Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 15, 2014 Share Posted April 15, 2014 Yes, Blackgames is right, something like this: function create() { buttonA = game.add.sprite(100, 100, 'buttonA'); buttonA.variable = "Hi there!" buttonA.inputEnabled = true; buttonA.events.onInputDown.add(doSomething, this); } function doSomething (item) { console.log(item.variable); } mtburdon and Pooya72 2 Link to comment Share on other sites More sharing options...
adamyall Posted April 15, 2014 Share Posted April 15, 2014 Similar question:http://www.html5gamedevs.com/topic/5351-call-a-function-with-arguments-when-oninputdown/ Link to comment Share on other sites More sharing options...
mtburdon Posted April 16, 2014 Author Share Posted April 16, 2014 Thanks guys, I managed to sort it with your brilliant help! The code example from Pedro Alpera was particularly helpful. Thanks again all! Link to comment Share on other sites More sharing options...
Recommended Posts