If Statement help – Flash Actionscript 2.0

actionscript-2buttonflash-cs5if statementmovieclip

This is probably going to be a long shot, because I'm having trouble articulating what I'm attempting, but I will try anyway. 🙂

My overall concept is a basic (very basic) game; you have ingredients (4 of them) and depending on which ones you choose, the final product (in this case, a cake) looks different.

For example: if you click the "cake mix" button, the "chocolate" button and the "water" button, you get CHOCOLATE CAKE. But if you only click the "cake mix" button and the "water" button, you get VANILLA CAKE.

I have no idea how to code it so that, depending on which buttons are clicked, you get a different outcome. Any ideas? =/

There is a "REVEAL" button that I'm putting all of the script on. Right now I have:

on (release) {
if (_root.buttons.water._visible == false);
gotoAndPlay(384);

if (_root.buttons.water._visible == true);
gotoAndPlay(383);

}

I'm trying to say, if at any point the water button is clicked, go to THIS OUTCOME (frame 384). But if the water button HASN'T been clicked, go to THIS OUTCOME (frame 383).

Hopefully someone has an idea I can try! 🙂

I am using Flash CS5 and Actionscript 2.0. Thank you!

Best Answer

You probably need to set some state variables for each button first, to keep track of what's been clicked and what hasn't. Something like:

var cakeMixSelected = false;
var waterSelected = false;
var chocolateSelected = false;

When one of these is released, change switch its variable to "true".

Then the if statements in your check should look something like this:

if(waterSelected == true) {
    if(cakeMixSelected == true && chocolateSelected == true) {
        //go to chocolate code here
    } else if (cakeMixSelected == true) {
        //vanilla here
    } else {
        //water only here
    }
} else {
    // no water code here
}
Related Topic