• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Persistent objects and variables

PWL

Member
Quick question. Are variables supposed to carry over with persistent objects, or are they deleted when I chance rooms?
And if they are destoryed, why do I need persistent objects if I have to use global variables anyway?

Code:
// Create event
currentRoomX = 5;
currentRoomY = 5;

room_goto(room_level);
Code:
// Room start event
show_message(currentRoomX); // <-- Instant error
 

Simon Gust

Member
Quick question. Are variables supposed to carry over with persistent objects, or are they deleted when I chance rooms?
And if they are destoryed, why do I need persistent objects if I have to use global variables anyway?

Code:
// Create event
currentRoomX = 5;
currentRoomY = 5;

room_goto(room_level);
Code:
// Room start event
show_message(currentRoomX); // <-- Instant error
That's weird huh, I think it might have something to do that persistent objects don't rerun their creation code. But I don't know why it would forget them if they are persistent.
 

dannyjenn

Member
The variables should remain until the instance is destroyed.

Regarding the error - So, you have the instance in a room, and you change rooms and get the error? Or, you get the error on the very first room?
If the latter, it's because (I think) the room start event comes before the creation event.
 

Simon Gust

Member
The variables should remain until the instance is destroyed.

Regarding the error - So, you have the instance in a room, and you change rooms and get the error? Or, you get the error on the very first room?
If the latter, it's because (I think) the room start event comes before the creation event.
The manual states that the creation event is always first so it must be something else.
 

PWL

Member
The manual states that the creation event is always first so it must be something else.
Thanks all for your replies.

The create event should not fire when I enter the next room, because the object was created in the previous room.

I can confirm that the create event has happened and that it happens once, then the room start event fires (in the next room I suppose, because I change rooms in the create event), and then get the error. The create event is not fired in the second room, and neither is it my intention.

Edit: Correction, it is placed in the first room and not created by code. If that matters.
 

chamaeleon

Member
Is the error due to trying to call show_message() with a number instead of a string? Try
Code:
show_message(string(currentRoomX));
 

PWL

Member
Is the error due to trying to call show_message() with a number instead of a string? Try
Code:
show_message(string(currentRoomX));
Oh god.. It was a typo in my code there.

And with that fixed, it lead me to the original error that caused me to test with a simple variable.
My ds_grid did not exist. Reason: I destroyed them all in the Room End event to prevent memory leaks. :bash:

Thank you all!
 
Top