Page 1 of 2

Multiple If....

PostPosted: Thu Nov 16, 2006 11:49 pm
by Diana Kennedy
I would like to do the following thing: According to the final score, I would like to make the game creating a "medal" actor at the end of the game. I a silver for a score less than 200 (tin) one for greater than 200 but less than 500 (silver) greater than 500 but less than 1000 (gold) and so on.

I have that bit of code from another project:

Code: Select all

if (score.textNumber>=130)
CreateActor("tin", "tinmedall", "no parent", "no path", 0, 14, true);

else if (score.textNumber<130)
CreateActor("g", "gameover", "no parent", "no path", 2, -6, true);



But it would probably be need to be adjusted. Which would be the right code for these multiple options?

PostPosted: Thu Nov 16, 2006 11:54 pm
by Game A Gogo
it should be
Code: Select all
if (score.textNumber>=130)
{
CreateActor("tin", "tinmedall", "no parent", "no path", 0, 14, true);
}

else if (score.textNumber<130)
{
CreateActor("g", "gameover", "no parent", "no path", 2, -6, true);
}

PostPosted: Fri Nov 17, 2006 12:28 am
by Diana Kennedy
And then so on? I mean for all the other possibilities?

PostPosted: Fri Nov 17, 2006 12:41 am
by Game A Gogo
you could do like
Code: Select all
if(score<200)
{
Tin medal action...
}
else if(score>=200 && score<500)
{
silver...
}
else if(score>=500 && score<1000)
{
gold
}

and so on...

PostPosted: Mon Nov 20, 2006 1:30 am
by Diana Kennedy
Hm, it did not work. Either it says "syantax error" or it works in the way that it changes the score to 500 itself at the end of the game...

PostPosted: Mon Nov 20, 2006 1:46 am
by Joat_Mone

PostPosted: Tue Nov 21, 2006 4:50 am
by DilloDude
Game A Gogo wrote:
Code: Select all
if(score<200)
{
Tin medal action...
}
else if(score>=200 && score<500)
{
silver...
}
else if(score>=500 && score<1000)
{
gold
}
You won't need to test the greater than with an else. Rather than check twice, just use
Code: Select all
if(score<200)
{
    Tin medal action...
}
else if(score<500)
{
    silver...
}
else
{
    gold
}

PostPosted: Tue Nov 21, 2006 10:38 pm
by Game A Gogo
well, she said and so on, which meen there will be more then gold, maybe like saphire.

PostPosted: Sat Nov 25, 2006 4:29 am
by Diana Kennedy
Yes.

Hm...I still got troubles. Look what it says:

Image

PostPosted: Sat Nov 25, 2006 5:13 am
by DilloDude
Is 'score' a previously declared variable?

PostPosted: Sat Nov 25, 2006 1:20 pm
by Fuzzy
double check the upper/lower case spelling of score?

PostPosted: Sat Nov 25, 2006 1:28 pm
by sonicfire
Is "score" defined and global?

by the way : you should really use case and break here.

Lets assume score is 800. I assume you want to give the player only ONE medal (e.g. either silver,gold or platin).

So with your if code, the player would get two medals then, since its bigger than 200 AND bigger than 500...

hope that makes sense :)

PostPosted: Sun Nov 26, 2006 12:00 am
by DilloDude
Using a switch would not work, because you want to check a range. You'd have to have a case for every single possibility, which could be up to 1000 cases, depending on the maximum score. Because you are checking with 'less than' and 'else' you avoid getting more than one thing happening.

PostPosted: Sun Nov 26, 2006 3:09 pm
by Fuzzy
with a switch() you could put the number in a temp var, divide by 100 and drop the faction, then you would only need say, 10 cases.

PostPosted: Tue Nov 28, 2006 1:08 am
by Game A Gogo
make it
Code: Select all
if(score<200)

not
Code: Select all
if{score<200}

if thats not it, then i must be blind, (its hard to see because of the BG of the window)