Alice Community  

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

Reply
 
Thread Tools Display Modes
Boolean Functions
Old
gdev
Guest
 
Status:
Posts: n/a
Default Boolean Functions - 03-12-2007, 11:39 AM

I have created a Boolean function to do crash detection.

I have:

if (distance between objectes < 1)
then return = true
else return = false

return = true

The last return = true is there from when I first created the function. The problem is when this runs it always returns true thanks to the last return statement. I have an example of something similar from our textbook and they have the last return = none but I cannot find any place that I can set that return to none. Please Help.
   
Reply With Quote
Return from Boolean function
Old
DrJim
Guest
 
Status:
Posts: n/a
Default Return from Boolean function - 03-13-2007, 12:19 AM

Here is a start on the answer. (This explaination could really use some more rigor in defining terms and elsewhere - I'd appreciate any help there.)

Your basic problem is that you are trying to use "Return" - which is a reserved word for the value returned from a function - as an ordinary variable in the body of the function itself. This actually will work (which surprises me a bit ) if you declare a local Boolean variable named "Return" and then "Return 'Return' " (see attached) - but it's a very bad idea.

A much better appoach is to declare some other local variable name in the function and set up your tests to set its value - then return it using the "Return" line in the function template.

As far as the "Return '<None>' " statement - that is only an allowed option for a function type, such as a texture (again see attached), for which <none> is an allowed value to return for the variable. For a Boolean function, you must (and will be forced by Alice to) ultimately return either a true or false.
Attached Files
File Type: a2w Return Demo.a2w (171.3 KB, 325 views)
   
Reply With Quote
Thanks but...
Old
gdev
Guest
 
Status:
Posts: n/a
Default Thanks but... - 03-13-2007, 07:46 AM

Thanks for the response. I see what you are doing but the problem is that where we are in the textbook we haven't introduced variables yet, and the book tells you to create exactly what I have done and they have a return none. I attatched what the book has done and it works just fine the only problem is that I can't reproduce what they have done. Please help.
Attached Files
File Type: a2w Ch06Lec2aFlightCollision-V2.a2w (1.32 MB, 309 views)
   
Reply With Quote
I can't duplicate/explain it either.
Old
DrJim
Guest
 
Status:
Posts: n/a
Unhappy I can't duplicate/explain it either. - 03-13-2007, 11:04 AM

I can't reproduce it either - once I get rid of the <none> as an arguement for the Return, I can't get it back (which is, in my opinion, the "correct" way for the template to have been set up - but doesn't help you if you are supposed to "duplicate the book").

The text itself (p.159) never actually shows the "Return <none>" line, only the if/else statement. With that if/else statement, the "Return <none> line doesn't really matter, since the function will always return to the calling method before it gets to that line - but I can't explain why your program contains that line or how to duplicate it - nor do I think such a statement should be allowed in a Boolean function - but since it does no harm ???

I though it might be listed as an error in the errata sheet, but the latest reference I have for the errata for the text, http://www.aliceprogramming.net/text/errata.pdf , doesn't list it. Anyone have a newer version or some explaination for this.
   
Reply With Quote
thanks
Old
gdev
Guest
 
Status:
Posts: n/a
Default thanks - 03-13-2007, 11:32 AM

thanks for the help. The other teacher who teaches this and I have not been able to figure it out at all. I agree that using a local variable makes the most sense but I'm still intrigued why our book decided to add this in before we did variables. Oh well. Looks like I'm introducing variables tommrow in class.

Thanks again.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-13-2007, 10:14 PM

Quote:
Originally Posted by gdev View Post
I'm still intrigued why our book decided to add this in before we did variables.
It is intriguing - I'd never really gone throught the Dunn, et al, text from front to back and hadn't realized that variables were treated so late in the book until this question came up. Maybe one of the authors will read this thread and add some insight.
   
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.