GML Global Variables not being updated

E

Ellys

Guest
Hey coders, I initialise all my global variables in my first page. When i move into a fight i want the if/else statements to allow for me to create a battle system but the global variables are not being updated. (Also to note the global.MonsterSpeed> global.Spd is always called even if Spd is larger than MonsterSpeed. The randomNumb1/2/3/4 are all local variables)

if mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, oRush)
{
if mouse_check_button_released(mb_left){
if (global.MonsterSpeed> global.Spd)
global.HP -= 10;
show_message("The beast is quicker than you, you have taken damage")
}
else if (global.MonsterSpeed = global.Spd){
global.HP -= randomNumb2;
global.MonsterHealth -=randomNumb3;
show_message("The beast has evenly matched your rush attack, you both take a small amount of damage");
}
else if (global.Spd > global.MonsterSpeed) {

global.MonsterHealth -= randomNumb4;
show_message("You catch the beast off guard. The beast takes a devastating blow");
} }

//This is my INITIALISE code:
global.Spd = 5;
global.Popularity = 0;


global.MonsterHealth = random_range(2, 5) ;
global.MonsterSpeed = 1;
global.MonsterGold = random_range(2,10);

//THIS IS WHERE I WOULD END THE FIGHT IF LOST:
if (global.Health <= 0){
show_message("You have won the fight, as a prize you gained " + string(global.MonsterGold))
global.MonsterGold += global.Gold;
room_goto(OutsideColusuem);
}
 

Warspite2

Member
Have you drawn the variables on screen to test and see if the events are actually running? Looks like you may have forgot to put some brackets by global.HP-=10. I'm not always a fan of 'else' but try it like this and see how it does. I only typed it like this so maybe you can see { } better...



if (mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, oRush))
{
if mouse_check_button_released(mb_left)
{
if (global.MonsterSpeed> global.Spd)
{
global.HP -= 10;
show_message("The beast is quicker than you, you have taken damage");
}
}
else
{
if (global.MonsterSpeed == global.Spd)
{
global.HP -= randomNumb2;
global.MonsterHealth -=randomNumb3;
show_message("The beast has evenly matched your rush attack, you both take a small amount of damage");
}
}
else
{
if (global.Spd > global.MonsterSpeed)
{
global.MonsterHealth -= randomNumb4;
show_message("You catch the beast off guard. The beast takes a devastating blow");
}
}
}

//This is my INITIALISE code:
global.Spd = 5;
global.Popularity = 0;

global.MonsterHealth = random_range(2, 5) ;
global.MonsterSpeed = 1;
global.MonsterGold = random_range(2,10);

//THIS IS WHERE I WOULD END THE FIGHT IF LOST:
if (global.Health <= 0)
{
show_message("You have won the fight, as a prize you gained " + string(global.MonsterGold))
global.MonsterGold += global.Gold;
room_goto(OutsideColusuem);
}
 
Top