Quote:
Originally Posted by ekat90
I'm obviously using alice I don't know how too add boolean (fishdead) I just got not a both a and b and either a or b, or both, i dont know how too add =isshowing. we've only been taught to click and drag methods and functions thus far.
The only way i thought you could tell alice its dead is by changing the opacity 0%. Sorry guys I'm a complete newbie I just hope i don't fail this assignment
the assignment restricts us from doing variables
|
My apologies, I didn't have alice open at the time and was unable to give a proper response.
A boolean is a type of function. You'll want to click the button that says create new function (I would recommend adding this function in your fish's functions rather than the world - as it is a common practice).
Next, type a name for the function. In your scenario, "fishDead" is a good name. Click the Boolean button and then select "OK".
Now that you have the boolean function created, you'll want to add code to it so when called, it performs a task. Drag the "If/Else" into the fishDead class. You'll see the following code:
Code:
if (true)
{
//Do Nothing
} else {
//Do Nothing
}
Return true;
As you have said you used opacity (rather than the property isShowing) you will need to check the opacity of the fish. To do this, go to the fish's property tab and locate the property "opacity". Drag and drop this property on the "true" in the fishDead class. Alice will ask you to select from several options. Select the option that says "opacity ==" and then select "other...". A custom number box will come up. Enter 0 (zero) into this box and select "Okay".
Your code for the fishDead class should now look something like this:
Code:
if (fish.opacity == 0)
{
//Do Nothing
} else {
//Do Nothing
}
Return true;
You will now want the code to return true or false. Since the if statement is asking if the fish's opacity is 0 (dead), you will return true signifying that the fish is dead. To do this, drag and drop the Return statement below the if statement and set it to "true".
Your code should now look something like this:
Code:
if (fish.opacity == 0)
{
Return true;
} else {
//Do Nothing
}
Return true;
Finally, you'll want to return false in the event that the fish's opacity is not 0 (this returns that the fish is still alive). To do this, change the return statement at the bottom of the class to "false". It would also be a good idea to add in some comments so others know what the function does.
Your finished code should look something like this:
Code:
//Using the fish's opacity as a guideline, checks to see if the fish is dead or not.
//If the fish's opacity is 0, the fish is dead and the function is returned true.
//If the fish's opacity is not 0, the fish is still alive and the function is returned false.
if (fish.opacity == 0)
{
//The fish is dead, so we return true.
Return true;
} else {
//Do Nothing
}
//The fish is still alive, so we return false.
Return false;
Now that you have a function created that checks if the fish is dead or not, you can use it in your code. Locate where the fish says "Yum!". You'll want to drag and drop an If/Else statement in that area. Next, you'll want to drag and drop the fishDead function onto the if statement so it looks like so:
Code:
if (fish.fishDead)
{
//Do Nothing
} else {
//Do Nothing
}
Since your goal is to only say "Yum!" when the fish is dead, you'll need to check if the fishDead boolean is false, rather than true. To do this, click the arrow next to fish.fishDead, hover over "logic", then hover over "fish.fishDead<none> ==", and finally select "false".
The code should now look like this:
Code:
if (fish.fishDead == false)
{
//Do Nothing
} else {
//Do Nothing
}
Great! Now that we have this, you'll want to perform an action only if the fish is alive. Drag and drop the "say" method into the if statement and set the text to "Yum!". It will look something like this:
Code:
if (fish.fishDead == false)
{
penguin.say("Yum!"); duration = 0 seconds
} else {
//Do Nothing
}
There you go! Problem solved! The penguin will now only say "Yum!" when the fish is alive.
Don't forget to add in comments to your code as this is important.
I hope you understood everything we did here, so next time you'll be able to do it on your own. If for any reason you failed to understand something provided here, PLEASE let me know. I'll be more than happy to help out.