Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Need help with college work please!
Old
ekat90
Junior Member
 
Status: Offline
Posts: 6
Join Date: Dec 2012
Location: melb
Default Need help with college work please! - 12-11-2012, 09:49 PM

I'm trying to make a penguin game, where when I've controlled the penguin so that when the penguin is close enough to a fish, its commanded to say yum and for the fish dissapear, thats all fine but my only dillemma is even though I make the fish dissapear when I run the penguin over the invisible fish the penguin still says yum!. This is really really frustrating me and no matter what i read or do I cannot make the penguin only say it once, after its eaten it! please I'd appreciate any help.
   
Reply With Quote
Old
ekat90
Junior Member
 
Status: Offline
Posts: 6
Join Date: Dec 2012
Location: melb
Default 12-11-2012, 11:20 PM

http://www.2shared.com/file/yDbI2spT/A1-Startup.html

link too the work please have a look. I'm restricted I can't use variations, do together or do in order.
   
Reply With Quote
Old
HaloMike117
Junior Member
 
Status: Offline
Posts: 8
Join Date: Dec 2012
Default 12-12-2012, 12:02 PM

Quote:
Originally Posted by ekat90 View Post
I'm trying to make a penguin game, where when I've controlled the penguin so that when the penguin is close enough to a fish, its commanded to say yum and for the fish dissapear, thats all fine but my only dillemma is even though I make the fish dissapear when I run the penguin over the invisible fish the penguin still says yum!. This is really really frustrating me and no matter what i read or do I cannot make the penguin only say it once, after its eaten it! please I'd appreciate any help.
Resolving this problem is quite simple by using an if statement to check if the fish has been eaten or not.

To do this, you'll want to create a boolean that checks if the fish is showing or not.
Code:
boolean fishDead()
{
     if (fish.isShowing == true)
     {
          return true;
     }
     return false;
}
Next, all you'll need to do is check if the fish is dead or not before executing the code where the fish says "yum!".

To do this, simply add the following if statement:
Code:
if (fishDead() == true)
{
     //say("Yum");
}
Simple as that!

Good luck (:
   
Reply With Quote
Old
mcelroy32400
Junior Member
 
Status: Offline
Posts: 7
Join Date: Sep 2012
Default 12-12-2012, 05:28 PM

I like HaloMike's answer. Another cheap/jimmy-rigged way of doing it is to make the fish move up (or down) like 20 meters (or however far away you want) when the fish is eaten the first time. This way the penguin will never get close to it again. You could do it as a class method, something like fishEaten. Make it move up (or down) in 0 seconds and that will launch the fish away immediately, removing the possibility of the penguin getting too close ever again. (Another variation is to create a dummy object where all the fish could immediately get moved to once they've been eaten, again using 0 seconds to make it happen as though it is a do together without actually using the Do together.)

Like I said, HaloMike has the better programming solution.
   
Reply With Quote
Old
Beans
Member
 
Beans's Avatar
 
Status: Offline
Posts: 41
Join Date: May 2012
Default 12-12-2012, 06:51 PM

REALLY easy thing to do:
Variables!
Make a variable: Fish_Eaten
or something, make it turn on if the
fish is eaten, and then add a infinite loop
of if Fish_Eaten is on do nothing, else do
(insert your code here) when you reach within a certain
spot of the fish.


Check out my Weeping Angels and Zombie game!
Dont forget to vote if I should make more Doctor Who stuff and Doctor Who game!
   
Reply With Quote
Old
ekat90
Junior Member
 
Status: Offline
Posts: 6
Join Date: Dec 2012
Location: melb
Default 12-12-2012, 09:18 PM

Quote:
Originally Posted by HaloMike117 View Post
Resolving this problem is quite simple by using an if statement to check if the fish has been eaten or not.

To do this, you'll want to create a boolean that checks if the fish is showing or not.
Code:
boolean fishDead()
{
     if (fish.isShowing == true)
     {
          return true;
     }
     return false;
}
Next, all you'll need to do is check if the fish is dead or not before executing the code where the fish says "yum!".

To do this, simply add the following if statement:
Code:
if (fishDead() == true)
{
     //say("Yum");
}
Simple as that!

Good luck (:
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

Quote:
Originally Posted by Beans View Post
REALLY easy thing to do:
Variables!
Make a variable: Fish_Eaten
or something, make it turn on if the
fish is eaten, and then add a infinite loop
of if Fish_Eaten is on do nothing, else do
(insert your code here) when you reach within a certain
spot of the fish.
the assignment restricts us from doing variables
   
Reply With Quote
Old
HaloMike117
Junior Member
 
Status: Offline
Posts: 8
Join Date: Dec 2012
Default 12-13-2012, 11:39 AM

Quote:
Originally Posted by ekat90 View Post
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.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.