Instance's Variables gets reset without a reason

S

Spongyoshi

Guest
Hello everyone! I have checked all the instances related to this particular one but I couldn't find anything. It works fine (it's has important configuration variables like "Which character you picked" or "Which event you're playing", etc..) but when it goes to a special room, all it's variables are reset to 0! It doesn't reset instantly however as it spawns the right character (character 0 or 1) but the camera gets to the wrong place since it's trying to focus on a character that doesn't exist! (Because it's something like "if character pick = 1 go to character 1 position OR if character pick = 0 go to character 0 position") And none of my instances resets the instance's variables and it's still the same one since it has the same index! Does anyone have any ideas from where the problem can arise? I'm very confused x_x
 

Simon Gust

Member
These instances that have their variables reset, are they persistent?
If so, did you place them in the special room by accident?
 
S

Spongyoshi

Guest
Only 1 instance gets reset and it is indeed persistent! I also checked and there's not another one in the room! It only appears in one room that you only access once, each time you start up the game!
 
Does this object have a Room Start Event? Which events does the object contain? Which event do you initialise the objects variables in?

Put a show_debug_message() in your objects events to get a handle on what's getting called and when.

Check that you only have one copy of the instance either using the debugger or drawing instance_number(object) to the screen.
 
S

Spongyoshi

Guest
I already checked the number of instances and there's no copy for this object!
The object has a Create Event (where everything is initialized) One Step Event and Five events corresponding to the arrow keys and spacebar!
I've never heard of "show_debug_message()" before! However, I'd need some help on how to correctly use it.
 
You can put show_debug_message() anywhere in your code and it will print out whatever string you put between the parentheses to the console window.

You could also try searching your code for the names of the variables that are getting reset.

Hmm...cant think of anything else right now. You might have to post the code for this object, it might shed more light on the problem.
 
S

Spongyoshi

Guest
I'll post the code here! Hope it'll helps finding the problem! If you need more explanation on this object, please tell me!
Information about object: Settings
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: true
Parent:
Mask:
Create Event:
set variable GameMode to 0
set variable EventPlayed to 0
set variable CharacterPick to 0
set variable SongSelected to 0
set variable LastPosition to 0
Step Event:
if number of objects Parallel Giant Slalom is Equal to 1
set variable GameMode to 1
Key Press Event for Key:
if number of objects MarioSelection is Equal to 1
if EventPlayed is equal to 13
go to room TUTObobsleigh with transition effect
if EventPlayed is equal to 8
go to room TUTOsnowboardcross with transition effect
if EventPlayed is equal to 3
go to room TUTOskeleton with transition effect
if EventPlayed is equal to 2
go to room TUTOskijump with transition effect
if EventPlayed is equal to 1
go to room TUTOskidescente with transition effect
if EventPlayed is equal to 0
go to room TUTOsnowboardslalom with transition effect
if number of objects Parallel Giant Slalom is Equal to 1
go to room CharacterSelect with transition effect
Key Press Event for Key:
if number of objects Parallel Giant Slalom is Equal to 1
set variable EventPlayed relative to -1
if EventPlayed is smaller than 0
set variable EventPlayed to 0
if number of objects MarioSelection is Equal to 1
if CharacterPick is equal to 1
set variable CharacterPick to 0
else
set variable CharacterPick to 1
Key Press Event for Key:
if number of objects Parallel Giant Slalom is Equal to 1
set variable EventPlayed relative to -5
if EventPlayed is smaller than 0
set variable EventPlayed relative to +5
Key Press Event for Key:
if number of objects MarioSelection is Equal to 1
if CharacterPick is equal to 1
set variable CharacterPick to 0
else
set variable CharacterPick to 1
if number of objects Parallel Giant Slalom is Equal to 1
set variable EventPlayed relative to +1
if EventPlayed is larger than 19
set variable EventPlayed to 19
Key Press Event for Key:
if number of objects Parallel Giant Slalom is Equal to 1
set variable EventPlayed relative to +5
if EventPlayed is larger than 19
set variable EventPlayed relative to -5
Also, this is some good tips, thanks! I'll edit this post if I find anything with it!
 

TsukaYuriko

☄️
Forum Staff
Moderator
Are you using an old version of GameMaker Studio, or maybe even GameMaker sans Studio? That object information copypaste looks oddly like something from 8.1 or earlier.

If so, check your global game settings and ensure that you're not using the option that treats uninitialized variables as 0. That sounds like the most likely cause that would explain a "reset to 0" to me.

If this is the source of your problems, you'll receive an error message upon encountering this situation after running the game. Try to make sense of the error message or post is here and we'll be able to help you out.
 
S

Spongyoshi

Guest
I am. I've put 8.1 in the tags of the post since I am using Game Maker 8.1
I'm indeed using the "unintialized variables as 0" option but even with this toggled off, the variable still gets reset.
 
S

Spongyoshi

Guest
Okay so this is indeed a bigger problem than I though and I really need your help everyone.
I've ran some tests and it seems that ALL variables gets resets when entering the new room and when I made a new room, it did that error again but the currently made rooms don't have this problem.
Do any of you know on which parameters, all variables gets resets on permanent instances? I have no idea how it does this and I don't even know how to reset all instances so it's very likely that it isn't in my code (or I just couldn't even recognize it)
Thanks a lot to any further replies! This would really help since it's a very puzzling problem for me :/

EDIT: So while I still have no idea why it does that, I found out that global variables do NOT get reset, thankfully! So I'll be able to find a workaround so it's not urgent but thanks if you reply with any idea of where it can come from because it's a bizzare problem!
 
Last edited by a moderator:
Top