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

GameMaker Upgrades not working

J

jaigantor

Guest
So I have a button that creates an object that follows the mouse and when that object clicks on a tower is given
upgrade ++;

this is working fine and the counter is going up but in a step event(i wasn't sure if this would work but it seems to partially) I have the code

if upgrade == 0
range = 100;
damage = 40;

if upgrade == 1
range = 125;
damage = 80;

if upgrade == 2
range = 150;
damage = 160;

if upgrade == 3
range = 175;
damage = 320;


this works fine for the range but for some reason, the damage boosts straight to the 320 even if the tower was just placed any help appreciated
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You are missing the curly brackets that links all the code to the "if" being used... So:

Code:
if upgrade == 0
{
range = 100;
damage = 40;
}

if upgrade == 1
{
range = 125;
damage = 80;
}
// etc...
The way you have it just now, only the "range" value is related to the "if" while "damage" is just being set regardless.
 
I was going to mention this in a previous thread of yours, but it's just as appropriate here.
It seems you have the notion that curly braces are only required when you have three or more aspects of code you want to be controlled by a preceding conditional, which is not true. It's two or more. Right now, your code essentially is running like this
Code:
if upgrade == 0
{
range = 100;
}

damage = 40;

if upgrade == 1
{
range = 125;
}

damage = 80;

if upgrade == 2
{
range = 150;
}

damage = 160;

if upgrade == 3
{
range = 175;
}

damage = 320;
As you can see, in each frame, damage starts again at 40, and eventually ends up as 320. Only the range is affected by the upgrade.

Also, does this really need to be in a Step event? Could you not just set the variables whenever you change the upgrade?
 
J

jaigantor

Guest
You are missing the curly brackets that links all the code to the "if" being used... So:

Code:
if upgrade == 0
{
range = 100;
damage = 40;
}

if upgrade == 1
{
range = 125;
damage = 80;
}
// etc...
The way you have it just now, only the "range" value is related to the "if" while "damage" is just being set regardless.

Thanks so much this worked appreciate it!
 
Top