Advertisement

How can I carry a variable to another room in GML?

Started by November 02, 2018 03:00 PM
2 comments, last by TheCyberFlash 6 years ago

I was wondering if anyone could help with a little Game Maker Studio thing that I'm stuck with.. 

I'm working on a tower defense game and I want to make a room dedicated to being a game over screen and having it show the wave you just achieved, (One day planning to have show you highest wave and current wave) but I'm a bit stuck as to how to save the variable and have it show up in another room. I don't understand how the 'persistant' feature works, Whenever i'm opening a new room it runs the 'create' event again so everything goes to 0.. Is there some way I can save a number and NOT overwrite it in a create event by mistake in the next room? And then run a draw string line to show it on the screen?

 

I feel like it should be 'simple' and I'm just missing something obvious. 

 

Thanks to anyone that can help in advance :)

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

I don't use GameMaker but I took a brief look over their documents to see if I could find a solution for you.

Persistent seems pretty straight forward:

So based on what I can tell you would use it like so:

Create and object to hold your variables like score, lives, health or whatever... Then in the object properties you would check the box for Persistent. Once this is done, you should be able to carry over your object with its members from room to room. You're pretty much using an invisible object to store you information as far as I can gather. :) 

https://docs.yoyogames.com/source/dadiospice/000_using gamemaker/008_defining objects.html

This video should help you as well:

https://www.youtube.com/watch?v=3iDcmbZdhLE

 

Programmer and 3D Artist

Advertisement

Okay okay yeah I can see my issue, Thank you for helping! It IS Straight forward :P  Its because I was always recreating a new object so it would run the create event so I just message that up a bit there. Woo. Glad it was simple :P Thanks again!

 

Edit: Just to clarify --

 

Persistent objects need to initialize only once, after which they will exist in every room without further effort. However if the game comes across a persistent object again it will re-run its create event. So my issue was I had my object in each room thinking that persistent meant it would keep the data between the object instances.. I just deleted other objects of the same type and have ONLY ONE which now works.

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

This topic is closed to new replies.

Advertisement