Page 1 of 1

IF statement isn't working

PostPosted: Mon Jan 02, 2006 6:39 am
by CGameMaker
Hi!

I just registered to the forums because I have a problem and the help file couldn't answer it. In my game, all the levels have a time limit. The time limit is the value of the actor "time". This value is decreased by one every second.

When the time limit reaches 0 (time.textNumber = 0), I need the player to die and a gameover text to appear. I also want the timer to dissapear. To do so, I have attached this script as a Timer event to the actor "time":

Code: Select all
time.textNumber = time.textNumber - 1;
if(time.textNumber = 0)
{
    DestroyTimer("time");
    DestroyActor("player");
    CreateActor("gameover", "icon", "no parent", "no path", 0, 0, true);
    DestroyActor("time");
}


But the event doesn't work - it just ignores the if() statement entirely and instead just sets the value of "time" to 0! Why is this?

PostPosted: Mon Jan 02, 2006 8:18 am
by twobob
Use == for conditional statements and = to assign a value to a variable
In your case change your script to:-
if(time.textNumber == 0)

PostPosted: Mon Jan 02, 2006 8:19 am
by CGameMaker
Nevermind, I solved the problem. I know now the reason why my if statement didn't work - Game Editor is based on C-style coding. For some reason, in C coding you need to use operands twice in if statements, unless it is < or >. (Why?) But == didn't work (the code did not operate at all), so I found a different method: I changed the if statement so that it now checks to see if the time is below 0, which is good enough for me.

I suppose this topic can be closed/deleted now.