ItsBobo Posted June 28, 2016 Share Posted June 28, 2016 Hi, I'm new to phaser and so this might be a basic question. I did see: but that did not work for me. This code works: create: function() { image.events.onInputDown.addOnce(this.backToMenu, this); } backToMenu: function() { //do something } but create:function() { image.events.onInputDown.addOnce(this.backToMenu, {test: 0}); } backToMenu: function() { //do something with this.test } does not work at all. If you need more code, I will show you an example project. Thanks! Link to comment Share on other sites More sharing options...
ItsBobo Posted June 28, 2016 Author Share Posted June 28, 2016 I followed a tutorial so my code might look strange to some of you but https://github.com/debbarmaonit/BunnyDefender-HTML5-Game-With-Phaser/tree/master/Bunny%20Defender is basically the format of my code. For example, I have the create function inside a script and the backToMenu is inside the same script. Link to comment Share on other sites More sharing options...
rich Posted June 28, 2016 Share Posted June 28, 2016 Like this: image.events.onInputDown.addOnce(this.backToMenu, this, 0, {test: 0}); backToMenu: function(sprite, pointer, yourObjectHere) { // Your object ({test}) only appears after the default arguments } Link to comment Share on other sites More sharing options...
ItsBobo Posted June 28, 2016 Author Share Posted June 28, 2016 13 hours ago, rich said: Like this: image.events.onInputDown.addOnce(this.backToMenu, this, 0, {test: 0}); backToMenu: function(sprite, pointer, yourObjectHere) { // Your object ({test}) only appears after the default arguments } Sorry to bother you again, but why does it say 'undefined' when I click exit? Link to comment Share on other sites More sharing options...
rich Posted June 28, 2016 Share Posted June 28, 2016 Log it out. Inside 'backToMenu' do this: console.log(arguments). Then look at the output in the dev tools and see if your object appears anywhere. Link to comment Share on other sites More sharing options...
ItsBobo Posted June 28, 2016 Author Share Posted June 28, 2016 25 minutes ago, rich said: Log it out. Inside 'backToMenu' do this: console.log(arguments). Then look at the output in the dev tools and see if your object appears anywhere. Sorry if I don't understand, Dev tools doesn't have an output tab. How do I view that? Also, would it be easier if I just attach my code with my post so you can look at it? Thanks! Link to comment Share on other sites More sharing options...
rich Posted June 28, 2016 Share Posted June 28, 2016 Click 'console', click your button, and see what gets output there. Also you're using a pretty old version of Phaser (2.0.4). We're up to 2.5.0 now. I'm not even sure your version has support for input arguments. Link to comment Share on other sites More sharing options...
ItsBobo Posted June 28, 2016 Author Share Posted June 28, 2016 I updated my phaser and my game broke completely. If you can take a look at it, this would be great. @rich Link to comment Share on other sites More sharing options...
rich Posted June 28, 2016 Share Posted June 28, 2016 I don't mind fielding a few questions on the forum or slack, but I don't have time to download zip files and set things up and debug it all, sorry. Maybe someone else will, but at the very least the game ought to be uploaded somewhere so we can visit a simple URL instead of having to do anything locally. Also, try posting the actual errors you get in the console. If you don't know how to use the console, spend some time on YouTube watching tutorials on it, because it's invaluable. Link to comment Share on other sites More sharing options...
Recommended Posts