View Full Version : Hmmm... a little help? How do I create a Function do do this:
ragtop12
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
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.
ragtop12
03-16-2007, 12:42 PM
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.
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.