• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

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

xflcy

Member
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.
 

xflcy

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.
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