Before you go any further, save a copy of the world from the previous page as M9-DropShip-pg5-Nested-YourName.a2w
Just like with our either/or/orBoth compound boolean expression, our both/and compound boolean expression can be represented using nested if/else statements.
Let's analyze what happens when we want the dropShip to take off again:
if sphere is blue AND
sphere2 is blue AND
sphere3 is blue
then the space ship should take off
Let's revisit our compound boolean expression from 9.4:
We need to figure out how to check to make sure each of the spheres is blue and only have the spaceship take off if all three are blue, but without using a both/and tile.
To figure this out we should break our English statement into smaller pieces.
We need to:
Check if sphere is blue
If it is: Check if sphere2 is blue
If it is: Check if sphere3 is blue
If it is: The dropShip should take off
If it isn't: Nothing should happen
If it isn't: Nothing should happen
If it isn't: Nothing should happen
We will now work together to build up our entire nested if/else statement:
First, take out the both/and tile from your if/else tile:
Now add back in the check to see if sphere is blue and add the code that makes the dropShip take-off:
[Q9.5.1]: If you were to push play, when do you think the dropShip take off?
We want the dropShip to take off if all the spheres are blue, not just sphere, so we need to add another check. Before you have the dropShip take off, we need to also check if sphere2 is blue.
[Q9.5.2]: We need another if/else tile, where do you think it should go?
A. Before the if/else tile we already have
B. Inside the if part of the if/else tile
C. Inside the else part of the if/else tile
D. After the if/else tile we already have
And why?
Add the second if/else tile inside the if part of the if/else tile we already have:
Then add the check to see if sphere2 is blue in our nested if/else tile and move the dropShip take-off inside the second if:
Now add the third nested if/else with the conditional that checks if sphere3 is blue and add the move the statement that makes the dropShip take-off inside the most nested part of the nested if/else's to make the dropShip move up 30 meters:
Click play. Keep clicking the switch until you get all three spheres to be blue. Did the dropShip take off when all spheres were blue? Make sure the dropShip doesn't take off when there is a sphere that isn't blue though!
[Q9.5.3]: Where would you add the code that will cause the dropShip to say "Not taking off yet!" if any of the spheres are not blue?
Remember to save your world from this page as M9-DropShip-pg5-Nested-YourName.a2w