Having trouble sending data to a new scene

Hello,
I am trying to open a new scene after the user clicks a button and also give some data to the new scene but the other scene doesn’t detect the data.
This is part I send data from MainScene.js (starting point)
1
The data type is a string but it doesn’t matter whether i use a int or array.

This is the scene I am trying to open (“PaintScene.js”):
2

The data variable is always like this:
33

Lose the quotes around the data you’re passing.

I made small changes to it but it still doesn’t work.

22

33

I am not sure but maybe it’s because I made a mistake creating a new scene? By the way, I am opening up a new scene from another scene if that makes a difference.

This is a good example:

Thanks for the resource, it’s been a good read.

What I am trying to accomplish in my game is to switch scenes instead of adding scenes on top of each other. There will be a main menu where people will join games and a game scene where game will be played.

If that’s not possible, I have an idea of making a scene that networking will be done and is never closed.

My point was, if you use that example and pass data, you see it works :slight_smile:

My scenes are all in different files though if you mean the global ‘game’ variable. Other than that, I don’t really see where they passed data between scenes in that example.

Just add an init, pass. and see it work. It shows how to setup scenes.
If you put your code online somewhere it’s easier to spot the problem.

Here:
PaintScene.js
MainScene.js
index.html

That’s not good enough :slight_smile:
I mean a fiddle, codepen, codesandbox etc.

If you mean the whole project, here is the zip: https://easyupload.io/yv8var

Just update your Phaser version (you’re using 3.0.0 :wink: ).

<script src="//cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.min.js"></script>
1 Like

Ahh, that explains a LOT of things, thank you! It’s now working like a charm.