Why isnt this working?

Game Editor comments and discussion.

Why isnt this working?

Postby ThaKid244 » Wed Jun 15, 2011 7:19 pm

Hi. I am in the middle of creating a new game but I am having a problem with variable counting.
I have a variable named "P".
I have an actor (Pcounter) that has animations of numbers eg. "one" "two" "three" "four" "zero"
When "P" equals one "one" is displayed, as for two and so on.
I have another actor which is supposed to (upon creation of an actor) make P = 0;
It is not working for some reason because my Pcounter always displays a one.
Can someone help?
Attachments
Pcounter.ged
This is the example I am having trouble with
(1.83 KiB) Downloaded 85 times
K Thanks! ;)
User avatar
ThaKid244
 
Posts: 34
Joined: Thu Dec 23, 2010 6:40 pm
Score: 0 Give a positive score

Re: Why isnt this working?

Postby foleyjo » Wed Jun 15, 2011 8:22 pm

I think it's your if statement

I think it should be
Code: Select all
if (p==0) etc
if(p==1)etc


Also a switch statement might be better

Code: Select all
switch (P)
{
case 0:   ChangeAnimation("Event Actor", "zero", FORWARD); break;
case 1:   ChangeAnimation("Event Actor", "one", FORWARD); break;
}
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Why isnt this working?

Postby foleyjo » Wed Jun 15, 2011 8:30 pm

Actually the better people on this forum might suggest you also try

Code: Select all
ChangeAnimation("Event Actor", getAnimName(P) , FORWARD);
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Why isnt this working?

Postby ThaKid244 » Wed Jun 15, 2011 10:29 pm

Thanks foley. Could you explain what the case statement does and why is there a "break;" afterwards?
K Thanks! ;)
User avatar
ThaKid244
 
Posts: 34
Joined: Thu Dec 23, 2010 6:40 pm
Score: 0 Give a positive score

Re: Why isnt this working?

Postby skydereign » Thu Jun 16, 2011 12:06 am

That is just how a switch statement works. The variable in the () at the beginning of the switch is the variable you are checking (like in an if statement). The actual cases are the values. So case 0 means if the variable equals 0.
Code: Select all
switch(var)
{
    case 0:
    // execute code here until the next break statement
    break;

    case 3:
    // execute this code here until the next break statement
    break;
}


So as the above code says the break is a way of determining the end of a case statement (kind of like {} in an if statement.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Why isnt this working?

Postby foleyjo » Thu Jun 16, 2011 7:24 am

skydereign explained it better than I could.

The break statement exits the switch. If you don't have it the next case will also be used so if P = 0

Code: Select all
switch (P) 
case 0: X = 0;
break;
case 1: X = 1;
break;



Will make X = 0

Code: Select all
switch (P)
case 0: X = 0;
case 1: X = 1;


Will make X = 1

I know this because I have made the mistake of not using break before
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron