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

Global Variables not working

K

KevDoesArt

Guest
I have a obj_variables that is persistent that handles all my global variables for my game. Here is what the code looks like right now

In Create

globalvar foyerdark;
foyerdark = false;

In Step

if foyerdark = true {
with (obj_Foyer) && (obj_picframe_foyer){
image_index = 1;}
}

if foyerdark = false {
with (obj_Foyer) && (obj_picframe_foyer){
image_index = 0;}
}

I have an object in the room that when the player collides with changes foyerdark from false to true but it's not doing anything. I have rewritten the code with and without brackets around the foyerdark = true/false and tried everything I know. I can't seem to get it to work. I also need it to work across rooms so that this code can be triggered from another room - hence the persistence on the obj and the rooms themselves.

Code for trigger object

In Collision

foyerdark = true;
 

obscene

Member
A couple of things. First use global.foyerdark instead, apparently they are killing globalvar at some time in the future so get in the habit of not using it.

Second, you can't do this: with (obj_Foyer) && (obj_picframe_foyer). with can only have one subject at at time. && is for comparisons ( if a==2 && b==3 ) not for instructions ( do this && do that ) as you tried to do. This might fix your problem is you just rewrite this section, if not just repost your new code and we'll figure it out.

Also sometimes it helps to just do something show_debug_message(global.foyerdark) at key points in your code so you can track in your console if the values are as you expect... or try drawing them to screen for testing.
 
K

KevDoesArt

Guest
A couple of things. First use global.foyerdark instead, apparently they are killing globalvar at some time in the future so get in the habit of not using it.

Second, you can't do this: with (obj_Foyer) && (obj_picframe_foyer). with can only have one subject at at time. && is for comparisons ( if a==2 && b==3 ) not for instructions ( do this && do that ) as you tried to do. This might fix your problem is you just rewrite this section, if not just repost your new code and we'll figure it out.

Also sometimes it helps to just do something show_debug_message(global.foyerdark) at key points in your code so you can track in your console if the values are as you expect... or try drawing them to screen for testing.

Thank you! That worked perfectly!
 
Top