Multiple If....

Non-platform specific questions.

Multiple If....

Postby Diana Kennedy » Thu Nov 16, 2006 11:49 pm

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?
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Game A Gogo » Thu Nov 16, 2006 11:54 pm

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);
}
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Diana Kennedy » Fri Nov 17, 2006 12:28 am

And then so on? I mean for all the other possibilities?
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Game A Gogo » Fri Nov 17, 2006 12:41 am

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...
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Diana Kennedy » Mon Nov 20, 2006 1:30 am

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...
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Joat_Mone » Mon Nov 20, 2006 1:46 am

Joat_Mone
 
Posts: 37
Joined: Mon Mar 01, 2004 9:13 pm
Score: 0 Give a positive score

Postby DilloDude » Tue Nov 21, 2006 4:50 am

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
}
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Game A Gogo » Tue Nov 21, 2006 10:38 pm

well, she said and so on, which meen there will be more then gold, maybe like saphire.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Diana Kennedy » Sat Nov 25, 2006 4:29 am

Yes.

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

Image
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby DilloDude » Sat Nov 25, 2006 5:13 am

Is 'score' a previously declared variable?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Fuzzy » Sat Nov 25, 2006 1:20 pm

double check the upper/lower case spelling of score?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby sonicfire » Sat Nov 25, 2006 1:28 pm

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 :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Postby DilloDude » Sun Nov 26, 2006 12:00 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Fuzzy » Sun Nov 26, 2006 3:09 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Game A Gogo » Tue Nov 28, 2006 1:08 am

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)
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest