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

Legacy GM Global Variable only interacts with last instance in room and not all

T

thrash

Guest
Hello together,

not sure if I do something wrong or if gamemaker trolls me, but...

I have a global variable named global.towerbuilder and set it to 0 when the room starts with a controller object.

I have some instances of an object in my room, which are places where towers are placeable (in the future), when my cursor object is hitting the tower place object, I set the global.towerbuilder to 1, and when I leave the place object with the cursor I set it back to 0.

The strange thing is, this only happens to the last added instance in the room, the other instances of the place object don't show any reaction.

At first I did this with a instance variable, but I need to acces the variable from other objects and thought a global variable was the best way, and now I'm sitting here, with only few days left (gbjam...) arrrrr.
Heres a .gif where you see my problem: https://www.dropbox.com/s/tu8atszcs07ugoe/globvartest.gif?dl=0

Heres the code of the place objects step event:
Code:
if (place_meeting(x,y, obj_mouse)) {
   image_index = 1;
   global.towerbuilder = 44;
   } else {
   image_index = 0;
   global.towerbuilder = 22;
   }
Hope you can enlight me... I have no idea and wasted so many hours of trying and figuring out. I set the numbers to 22 and 44 in my example, instead of 0 and 1, in case you are wondering.

thank you.
 
T

TesloStep

Guest
look, every of your objects change global.towerbuilder to 22 if there is no mouse on them, understand? you probably need work it in different way - set
global.towerbuilder in some begin step event of system obj to 22, and set them to 44 when mouse on yours placec
 

KhMaIBQ

Member
You will want to have that code in your mouse object instead of your place object.

The reason why it is not working is because ALL the objects are checking this. The last object you place in the room has the highest priority because it is the last object to check the code. For example...

1. Hover mouse on Place Object #1.
2. Place Object #1 detects this condition is true.
3. global.towerbuilder is set to 44.
4. Place Object #2 detects this condition is false.
5. global.towerbuilder is set to 22.

That is all occurring in a single step of your game.
 
T

thrash

Guest
Ahhhh, damn!
Thank you guys, I were so confused and thought about anything, except this.
So let's go finish this build system tonight.
 
Top