• 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!

Saving multiple instance positions on room start.

J

JealousOfCrows

Guest
Hey Game Makers!

Using 1.4.1567. (don't ask)

So I have a bit of a problem figuring out the best way to do this. Essentially, what I am trying to do is when my player dies, not have the room 'technically' restart but rather have enemies and moving platforms return to their initial positions. The reason for this is because I am trying to keep surface decals in the game like blood splatter and burn marks etc...after the player dies. This kind of symbolizes your failed attempts and just looks cool.

So is saving all the specific instances and positions I need at room start and then destroying them and respawning them when the player dies the best way to do this, or is there a more efficient way to like save the surfaces of the decals and redraw them with a formal room_restart?

I am at a loss on this problem, any help or suggestions will help! Let me know if you think a gif would help describe my situation.

Cheers,
 
J

JFitch

Guest
For each object, save the starting position as variables for that object.

If an object is destroyed but has a starting position, then deactivate it instead of destroying it, and reactivate it when resetting the position.
 

NightFrost

Member
Unless resetting the room to starting state is your goal, using room restart just for player respawn isn't really necessary. In the last project where I had multiple lives player respawn job acually fell to my UI controller object. Since it was already tracking score and lives, it also took the job of instace_creating a new player or moving to game over room. Solution like that just needs to know where to respawn the player.
 
J

JealousOfCrows

Guest
Thanks both of you for your ideas! When I was looking for help I was super tired and couldn't think of how to do it properly. I ended up just storing a list of the instances that need to be deactivated and then reactivated on room start and then looping through them when the player dies and reactivating the instances that were deactivated ( I used a variable to flag them as being deactivated right before deactivating them, not sure if this was necessary as I am not sure what happens when you try to activate an instance that hasnt been deactivated). For the objects that weren't getting destroyed it was as simple as resetting their variables on player death. Thanks for the tips, for anyone having the same problem here is my solution.

Code:
//Room Start if instance_exists(oWallFragile)
{
    List = ds_list_create();
    with(oWallFragile)
    {
        ds_list_add(other.List, id);
    }
}

//Step event if player dies
if ds_exists(List, ds_type_list)
    {
        var dsLength = ds_list_size(List);
        for (i = 0; i < dsLength; i++) {
            if (List[| i].Deactivated == true)
            {
                instance_activate_object(List[| i]);
            }
        }
    }
I have another question though. Currently this works fine, but now what if I have like 10-20 different objects that need to be reset each room. Any ideas on creating a list of lists that I can loop through and see if the list inside the master list exists and then loop through the ids to reactivate?
 

TheouAegis

Member
Starting positions are saved in the variables xstart and ystart (unless you overwrite them).

I'd personally just set aside as much space for lists as i might eventually need. Then you don't need to verify data structures.
 
J

JealousOfCrows

Guest
Thanks for the tip @TheouAegis I ended up scrapping the idea of a list of lists. As I can just keep adding ids to the list and loop through them all and check specific flags, atleast for fading platforms. For enemies I will just loop through all instances of the parent (stored in a list) and then check if they are deactivated and reactivate them at their starting position, else just move them to their staring position and states.
 
Top