• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker A question about persistence

AtKiba

Member
Hi everyone, this is the first time I post something in the forums and I'm very new to GML (but not to programming). I have a few questions about persistence and what would be the best approach.

I'm making a metroidvania (I know it's not the best idea for a first game) and my first idea was to make a master persistent object from the first room to handle some "global" variables, but the player object still had it's own variables (hp, max_hp, status, etc.), this became a problem when I implemented transition between rooms and I created a new player object in the new room.

I've heard about ds_maps but still haven't played with them, my next idea is to make the master object to hold the player variables, but I wanted to know what would be the best way to handle this, maybe a ds_map in the master object with the player variables, but the player still having the same variables, just copying them to the player object every time it is created in a new room and copying them from the player to the master object when a transition occurs.

Thanks in advance!
 

obscene

Member
If you player object is persistent, you won't have to create him in the next room and your problem will be solved, right? You just need code in your player, or your controller object, that on room start moves the player to the correct position in the room since he will still have the same x,y in the new room.
 

AtKiba

Member
If you player object is persistent, you won't have to create him in the next room and your problem will be solved, right? You just need code in your player, or your controller object, that on room start moves the player to the correct position in the room since he will still have the same x,y in the new room.
Thanks for your reply :) I already hace a controller object, my question is about the best way to handle all the variables. I don't want to have a persistent player, not every room will have the player on it.
 
C

Catastrophe

Guest
Well, if you're asking the best way, it's what most people do which is making your object persistent anyways, but shutting off input, visibility, whenever you're on a screen where the character isn't supposed to be present.

But it does depend on the complexity of the main character object. If it's simple, ds_maps may indeed be the best way. Additionally, rooms can be persistent as well, which may solve some of your problems if you didn't know about them. It may cause memory issues if you plan on having more than 100 large rooms or so, though.

But everyone has their own style. Yal, e.g. apparently shoves everything that may need saving sometime into ds_maps xD

Edit: ah, metroidvania. Yeah I would not use room persistence, not scalable.
 

obscene

Member
Well, I would personally try to avoid duplicating variables. If your controller object knows the health, or armor, or whatever it is, just let your controller object handle any changes to health or armor. No reason to duplicate it. Make it global if that's easier, as that's generally the point of global variables.
 
Top