Alice Community  

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

Reply
 
Thread Tools Display Modes
Hmmm... a little help? How do I create a Function do do this:
Old
ragtop12
Guest
 
Status:
Posts: n/a
Default Hmmm... a little help? How do I create a Function do do this: - 03-16-2007, 07:36 AM

Hey all... I am a CPSC tutor for the local College, and this is the 1st semester we are using Alice for our one class. Anyways, I have to learn as the students learn and am having some troubles with functions. What the students have to do is create a world with a cat and 3 spanish worlds. When a user clicks on the spanish word for cat (gato), the cat shakes his head up and down and if the user clicks on a word other than gato, the cat shakes his head no. The student is to create a function called isGato that does this. A parameter in isGato has to be called objectClicked.

I am uncertain if I can use If statements in the Function, or how I would go about doing this. I know the easy way to do this is by creating new events for each word, but the problem specifically wants you to create a function. Any help would be appreciated! Thanks!
Obed
   
Reply With Quote
Boolean Function
Old
gdev
Guest
 
Status:
Posts: n/a
Default Boolean Function - 03-16-2007, 07:41 AM

Create a boolean function. Have the function use an if statement to check if the word is correct. If it is have it return true if it is the wrong word have the function return false.

Just drag the if statement into the line above the return line in the function. Then drag the return statement into the then and else parts.

Or create a local variable that is returned for cleaner code. See the message a few down entitled Boolean Functions for some examples/more information.
   
Reply With Quote
Old
ragtop12
Guest
 
Status:
Posts: n/a
Default 03-16-2007, 12:42 PM

Quote:
Originally Posted by gdev View Post
Create a boolean function. Have the function use an if statement to check if the word is correct. If it is have it return true if it is the wrong word have the function return false.

Just drag the if statement into the line above the return line in the function. Then drag the return statement into the then and else parts.

Or create a local variable that is returned for cleaner code. See the message a few down entitled Boolean Functions for some examples/more information.
Thanks for the reply. For some reason, it wont let me drag the return statement into the else part of the conditional. Oh well, this is frustrating, lol

I also read that thread, and it didnt help me, ughies.
   
Reply With Quote
hmmm
Old
gdev
Guest
 
Status:
Posts: n/a
Default hmmm - 03-17-2007, 08:34 AM

I don't know why it won't let you drag return into the else portion. Make sure you are dragging return from the bottom list of options, it won't let you move the return that automatically is placed in a boolean function. Also make sure you have created a boolean function.

Also another option is to create a local variable that is boolean. Have the then part set it to true and the else part set it to false and then just use the return statement that is automatically there just return the variable. Hope that helps.
   
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.