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

Windows <SOLVED> My global variable edit resets every room and I'm not sure why

X

xflcy

Guest
I've tried heaps of different things to try and fix this but so far nothing has worked

This code is in a pickup item that effects your fire rate. This is in the collision with the player event

if (global.hasgun == true)
{
global.firedelay = global.firedelay + 0.1;
}


instance_destroy();

The object is ticked as persistent, but for some reason my global.firedelay variable resets back to the default of 0.75 for every room. I would appreciate any help
 

Plisken

Member
Which object is the global variable stored in? If not already, you'll probably want to store it in a "Control" object (an object that stores a bunch of variables that need to be remembered throughout the game)

Create a "Control" object, make it persistent, then place it in the room, then put that variable in the Control object. You can also use this object for other things like health, high score, etc...

At that point, it's not necessary to make it a global variable. You could just call it via "Control.firedelay". (although calling it globally is probably easier because you wouldn't have to check for the object) I think Global variables are a bit less efficient when it comes to performance, but don't quote me on that.
 
X

xflcy

Guest
Which object is the global variable stored in? If not already, you'll probably want to store it in a "Control" object (an object that stores a bunch of variables that need to be remembered throughout the game)

Create a "Control" object, make it persistent, then place it in the room, then put that variable in the Control object. You can also use this object for other things like health, high score, etc...

At that point, it's not necessary to make it a global variable. You could just call it via "Control.firedelay". (although calling it globally is probably easier because you wouldn't have to check for the object) I think Global variables are a bit less efficient when it comes to performance, but don't quote me on that.
Thank you so much for this, that has completely fixed the issues and everything

thanks for the info as well, it'll suck having to go back and change global variables into the control object but its worth it. Thank you
 
Global variables are a bit less efficient when it comes to performance, but don't quote me on that.
Well I'm going to :p If my memory isn't failing me terribly, global variables are actually the fastest accessing variables, followed by local variables (var), then instance variables, then with() then dot notation (instance.variable). However, the performance gained by these different methods of access are incredibly minor, so don't worry about them at all unless you are doing thousands of accesses every step.
 
Top