Page 1 of 2
Multiple If....
Posted:
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?
Posted:
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);
}
Posted:
Fri Nov 17, 2006 12:28 am
by Diana Kennedy
And then so on? I mean for all the other possibilities?
Posted:
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...
Posted:
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...
Posted:
Mon Nov 20, 2006 1:46 am
by Joat_Mone
Posted:
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
}
Posted:
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.
Posted:
Sat Nov 25, 2006 4:29 am
by Diana Kennedy
Yes.
Hm...I still got troubles. Look what it says:
Posted:
Sat Nov 25, 2006 5:13 am
by DilloDude
Is 'score' a previously declared variable?
Posted:
Sat Nov 25, 2006 1:20 pm
by Fuzzy
double check the upper/lower case spelling of score?
Posted:
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
Posted:
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.
Posted:
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.
Posted:
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)