smdool Posted February 12, 2018 Share Posted February 12, 2018 (edited) In Phaser 2.7.5 I'm trying to pass an object as a parameter from one state to another but the object is showing as undefined. Below is the code from GameState whereby I'm looking to pass an object containing a score, time and seconds. this.game.state.start( "Congratulations", true, false, { score: this.killedGerms, time: this.timeLabel.text, seconds: this.remainingSeconds }); Below is the CongratulationsState where the parameter, "data", is coming through as "undefined". init: function(data) { console.log('data', data); data = data || { score: 0, time: "00:00", seconds: 0 }; } Any ideas on where I have gone wrong would be greatly appreciated. Edited February 14, 2018 by smdool changed "null" to "undefined" Link to comment Share on other sites More sharing options...
Fenopiù Posted February 12, 2018 Share Posted February 12, 2018 Try to give data the default values when you declare it. Link to comment Share on other sites More sharing options...
jamespierce Posted February 13, 2018 Share Posted February 13, 2018 I honestly can't see anything wrong with your code snippets Something I like to do in such cases is to simply do a "console.log(arguments); return;" right at the start of the state's init method. Do you have a play link somewhere online to check it out? Link to comment Share on other sites More sharing options...
smdool Posted February 14, 2018 Author Share Posted February 14, 2018 Thanks for the suggestion @Fenopiù, I'll give that a go. I haven't got an link available at the moment @jamespierce, as soon as I do I'll let you know. Link to comment Share on other sites More sharing options...
jamespierce Posted February 14, 2018 Share Posted February 14, 2018 @smdool you said the data is coming through as null. Is it really null, or is it set as undefined? Because if there is no data passed to the CongratulationsState, then it would be undefined. If it is null, that means data was actually passed (it just so happens the data object has a value of null.) Link to comment Share on other sites More sharing options...
smdool Posted February 14, 2018 Author Share Posted February 14, 2018 @jamespierce It has showing as undefined in the CongratulationsState. I'll update my original post. Link to comment Share on other sites More sharing options...
jamespierce Posted February 14, 2018 Share Posted February 14, 2018 @smdool Okay so no data is passed at all then. Maybe you have another state.start('Congratulations'); call somewhere, which starts the CongratulationsState without passing anything? Sorry I can't be more helpful than that I would need to see the complete code for both states to say more. You can send me the files for these two states if you want to and I'll have a look at it. Link to comment Share on other sites More sharing options...
smdool Posted February 14, 2018 Author Share Posted February 14, 2018 Thanks @jamespierce. I think the issue is because I had previously been using phaser-state-transition.min.js to animate state transitions. I had recently stopped using phaser-state-transition while I was testing something out but hadn't removed the script tag from index.html. This appeared to be overriding the normal this.game.state.start function. Titus 1 Link to comment Share on other sites More sharing options...
jamespierce Posted February 14, 2018 Share Posted February 14, 2018 @smdool Ah that makes sense now! Something had to be overwriting the state.start() call. Glad you've figured it out! Link to comment Share on other sites More sharing options...
Titus Posted April 23, 2018 Share Posted April 23, 2018 @smdool Thanks for posting your solution. Same thing was happening to me and i'm not sure I would have figured that out without coming here! Link to comment Share on other sites More sharing options...
Recommended Posts