Hi! I know there are other topics out there regarding this, but I can’t understand them well due to how they load scenes differently from my project. I want to transfer health and ammo between scenes, this is my project.
https://playcanvas.com/project/978072/overview/[BETA]%20Distorted%20Forces
Hi @Cryptonaph,
Several ways to do that, for example the easiest but least elegant attach your data to the window global object:
window.gameData = {
ammo: 10,
health: 100
};
Now this object is accessible from any JS script.
Another way is to load your scenes additively from a master scene. That master scene can have a script that is responsible for holding the required data. Check this example on how you can add/remove scenes from a base scene:
https://developer.playcanvas.com/en/tutorials/additive-loading-scenes/
Could you say that again? I’m having trouble understanding this. Do you mean it can be accessed from anywhere? Or is that not possible? I only need it to be accessed by one script.
Assuming you meant “Now”, can I do window.
followed by any name to have data linked to different things? Or can it only be window.gameData
?
Also, can I add to game data in different scripts? Like, let’s say my ammo and health are in separate scripts, can this still work?
And lastly, how do I call from this global?
Wait! I might have figured it out on my own, one moment!
Nevermind, I still need to know how to add more values in different scripts.
I decided to take a different approach, I just have multiple gameDatas, one called window.vitals and one called window.gunData