Jump to content

init parameters is undefined


smdool
 Share

Recommended Posts

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 by smdool
changed "null" to "undefined"
Link to comment
Share on other sites

@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

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.

Link to comment
Share on other sites

  • 2 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...