IF statement isn't working

Non-platform specific questions.

IF statement isn't working

Postby CGameMaker » Mon Jan 02, 2006 6:39 am

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?
Making Games for all!

    Things that annoy me:
  • Admin'ing phpBB. It's so much better for me to use phpBB than to Admin it.
  • People replying to topics when I already have posted the solution.


For Game Editor :: Against Game Maker.
CGameMaker
 
Posts: 4
Joined: Mon Jan 02, 2006 6:10 am
Score: 0 Give a positive score

Postby twobob » Mon Jan 02, 2006 8:18 am

Use == for conditional statements and = to assign a value to a variable
In your case change your script to:-
if(time.textNumber == 0)
twobob
 
Posts: 33
Joined: Sat Sep 10, 2005 10:29 am
Location: England
Score: 2 Give a positive score

Postby CGameMaker » Mon Jan 02, 2006 8:19 am

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.
Making Games for all!

    Things that annoy me:
  • Admin'ing phpBB. It's so much better for me to use phpBB than to Admin it.
  • People replying to topics when I already have posted the solution.


For Game Editor :: Against Game Maker.
CGameMaker
 
Posts: 4
Joined: Mon Jan 02, 2006 6:10 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest