Groups | Blog | Home
all groups > flash actionscript > march 2004 >

flash actionscript : Look at this code - conditional


Lou (dog)
3/22/2004 11:37:49 PM
The code below goes in a game where I'm dropping clothes on a character and the
clothes that she's wearing when a button is pressed dictate the next step. As
you can see, there are several conditions that must be met, but this code isn't
working 100%. Some of it works, some doesn't. I'm sure it's my lack of
experience with actionscript. What I want to say is something like:

"If the dress is blue and the hat is leopard or pink hat OR if the dress is
leopard and the hat is asian, goto and play "newhat""

begin code------

on (release) {
trace(dress);
trace(hat);
if (dress == "pinkdress"){
gotoAndPlay("pinkdress");
}else if(dress == "bluedress" && hat == "leopardhat" || "pinkhat" || dress ==
"leoparddress" && hat == "asianhat"){
gotoAndPlay("newhat");
}else if(dress == "bluedress" && hat == "bowhat"){
gotoAndPlay("beautiful");
outfit = "blue";
}else if(dress == "bluedress" && hat == "asian" || dress == "leoparddress" &&
hat == "bowhat" || "pinkhat"){
gotoAndPLay("stylist");
}else if(dress == "leoparddress" && hat == "leopardhat"){
gotoAndPlay("leoapard");
}else if(dress == "asiandress" && hat == "asianhat"){
gotoAndPlay("asian");
}else if(dress == "dogfit"){
gotoAndPlay("dogfit");
}else if (dress == "duck"){
gotoAndPlay("duck");
}else{
gotoAndPlay("naked");
}
}
Laiverd.COM
3/23/2004 12:54:20 AM
Without rewritin the complete code, this should give you an idea

A line like:
} else if (dress == "bluedress" && hat == "asian" || dress ==
"leoparddress" && hat == "bowhat" || "pinkhat") {

Should be:
} else if ((dress == "bluedress" && hat == "asian") || (dress ==
"leoparddress" && (hat == "bowhat" || ("pinkhat"))) {

This is a pretty complex if-statement and I'm not even sure if the above
suits your needs. It is about proper nesting anyway. You may wanna consider
using the switch statement instead, which may produce more readable code.
Something like this:

switch (dress){
// first check for dress
case "bluedress":
// then check for hat
switch (hat){
case "bowhat":
dothings
break;
case "pinkhat":
dothings
break;
default:
dodefaultthings;
}
break;
case "reddress":
// then check for hat
switch (hat){
case "bowhat":
dothings
break;
case "pinkhat":
dothings
break;
default:
dodefaultthings;
}
break;
default:
dosomethingelse
}

There's more in the as-dictionary

John
--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Jeckyl
3/23/2004 10:54:41 AM
[quoted text, click to view]

THnk you need to read up on how to write conditions :)

[quoted text, click to view]

if ((dress == "bluedress" && (hat == "leopardhat" || hat == "pinkhat")) ||
(dress ==
"leoparddress" && hat == "asianhat")) {

AddThis Social Bookmark Button