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

SOLVED Creating array of obj position at start of game

T

Tonywryip

Guest
My goal: create an array that saves an obj's position in each room at the start of the game so that I can have call it later to have the game remember where the obj was before.

I am using GMS 2

step 1: saving obj position at start of the game

room order is r_menu, r_1, r_2, r_3, and r_4

GML:
if room == r_menu {
  
    for (var i = 1; i <= rm_max; ++i) {
        if room == room_last {
            room_goto(r_1);
        } else {
            room_goto_next();
        }
      
        global.rm_pos[i, 1] = room;
        global.rm_pos[i, 2] = o_player.x;
        global.rm_pos[i, 3] = o_player.y;
    }
}
this returns error trying to find o_player which exist in r_1 so I am thinking that it didn't actually go to r_1 but I have room_goto_next() so I am not sure what the problem is here.

and then the next step which I can't test because this step doesn't work goes like this (probably doesn't work

GML:
if next_room {
        rm_current = room;
        global.rm_pos[rm_current,2] = x;
        global.rm_pos[rm_current,3] = y;
        if !room_exists(room_next(room)) {
            room_goto(r_1);
            x = global.rm_pos[1,2];
            y = global.rm_pos[1,3];
            rm_current = r_1;
        } else {
            room_goto_next();
            ++ rm_current;
            x = global.rm_pos[rm_current,2];
            y = global.rm_pos[rm_current,3];
        }
    }
any help would be greatly appreciated! :D

SOLUTION: so turning on room persistent DOES work to keep all the instances in the same place. Although I still haven't figured out why this doesn't work.
 
Last edited by a moderator:

Sirham

Member
Could you do it at the start of each room? I don't think you can go through other rooms without visiting them.

You could also make the room persistent which does the same thing you want. Just without an array.
 
T

Tonywryip

Guest
Could you do it at the start of each room? I don't think you can go through other rooms without visiting them.
Ya I've recently changed the code so it doesn't record the x, y position at the start of the game but I still have some problems. (but also I would like to know why this doesn't work ;-; )

You could also make the room persistent which does the same thing you want. Just without an array.
the reason I don't want to make the room persistent is that then everything freezes in that room. I want to have things in that room that aren't persistent...

I will try to set the room persistent and instead of adding things to non-persistent rooms I will delete things from the persistent rooms :D

thanks for the help :)
 

Sirham

Member
Ya I've recently changed the code so it doesn't record the x, y position at the start of the game but I still have some problems. (but also I would like to know why this doesn't work ;-; )



the reason I don't want to make the room persistent is that then everything freezes in that room. I want to have things in that room that aren't persistent...

I will try to set the room persistent and instead of adding things to non-persistent rooms I will delete things from the persistent rooms :D

thanks for the help :)
No problem. Unfortunately there isn't ever a 100 percent solution to custom problems. But there's almost always a work around.
 
Top