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

Addition and subtraction of global variable doesn't work in another room

Solriva

Member
Hello community,
sry for wrong words if I use them. English is not my first language.

I have a problem with addition and subtration of numbers to a variable.

I used SetGlobalVariable to add 1 to a ressource called "money".
I created the variable before in an extra script.

SetGlobalVariable
money
8

then I added 1 to it by button press.
so object created with left pressed event and put

SetGlobalVariable
global.money
global.money+1

It works fine. As intended.

But now my problem.

I have in another room a second button which shall decrease money.
therefore I put the same in this button but -4 instead of +1

SetGlobalVariable
global.money
global.money-4

I get the sum: -278 ?? why

I tried to write the same as above again.
global.money+1

and I get the sum: 68

How can this happen? Where is this way too much value of 60 coming from? There are only these two buttons which change the global variable.

Note: The second buttons is placed inside another object and gets created by a different button.
to explain it simple. I click a region on my map and a popup with a button in it appears.
I dont know if this has something to do with this?

Much thanks for reading and hopefully helping.
 
Last edited:

chamaeleon

Member
Is the second button using the pressed event or not? If not, if it uses the down version of the mouse events, it will fire room-speed times per second.
 

Solriva

Member
I found the problem. It was a dumb idea to create the button instances in the Draw Event of the popup. I thought it only gets drawn once, but draw depends on this room speed you mentioned, yes?
Anyway thank you for your help.
 
Top