Alice Community How to make an object no move a certain distance -A cont of my last Q
 User Name Remember Me? Password

 Thread Tools Display Modes
 How to make an object no move a certain distance -A cont of my last Q
 george3356 Guest   Status: Posts: n/a How to make an object no move a certain distance -A cont of my last Q - 05-09-2011, 10:48 PM ASSIGNMENT: Make a rabbit chase a butterfly until it catches it w/ a net. I am now trying to make sure my butterfly does not go to high or to low - so high the rabbit can't reach/crashing into the ground. I know I need an if statement here, but I'm just not sure what to do with it. Any thoughts? (Again, I need to be sure the butterfly does not go to high or low using an IF/ELSE statement.)
 TauTrumpsPi Senior Member     Status: Offline Posts: 399 Join Date: Mar 2011 Location: The diamond layer 05-10-2011, 05:59 AM Just loop infinity times an if statement in a separate method that says if the butterfly goes too high, move down x meters. -------------------------------------------------------------------------------------------------------------------------- I have plenty of common sense. I just choose to ignore it. -Calvin and Hobbes Wondering about my Avatar? http://en.wikipedia.org/wiki/Tardigrade Wondering about my username? http://www.youtube.com/watch?v=jG7vhMMXagQ
 ieges Guest   Status: Posts: n/a 05-10-2011, 07:25 AM If butterfly distance away from ground is more than ____, then do _____- If butterfly is within .1 meters of ground, do _____ Be sure to loop these both infinitely, otherwise they will only check at the beginning of the world. I had this assignment also, so if you want, you can refer to it for help. The only thing I didn't do was loop the if statements infinitely, so remember to do that . (I think at least, but I could have missed something else) Assignment: http://www.dinkypage.com/113622 Oh, and also, here is what I think you need to use: Boolean butterfly.rise ( ) No variables If ( butterfly is within 0 meters of ground ) Return true Else Return false Boolean butterfly.fall ( ) No variables If ( butterfly is at least 1 meter away from ground ) Return true Else Return false From there, you can say in your myfirstmethod that if _____ returns true, do a method that makes the butterfly go up or down.
 dar Junior Member   Status: Offline Posts: 2 Join Date: Jun 2011 07-11-2011, 11:25 PM okay I was able to get all this to work but how do i keep the net with the rabbit everytime he moves until it catches the butterfly
 ElectricKirby Senior Member     Status: Offline Posts: 164 Join Date: May 2011 Location: Dreamland, Planet Popstar 07-12-2011, 03:36 AM Set the net's vehicle property to the rabbit. Preferable the hand he's holding it with. My Favorite Resources: Uploading Images - http://tinypic.com/ File Sharing - http://www.4shared.com/ Textures - http://www.filterforge.com/ Convertible Game-Ripped Models - http://models-resource.com/ Music - http://www.brawlcustommusic.com/gamelist
 help
letsgojets
Junior Member

Status: Offline
Posts: 3
Join Date: Aug 2013
help - 09-03-2013, 09:51 AM

I tried to follow the suggestion and I keep getting an error when trying to run, can you please review and let me know what i might have missed
Attached Files
 ClassWork8_1ButterflyChase.a2w (324.7 KB, 17 views)

 DensetsuNoKaboom Senior Member     Status: Offline Posts: 1,188 Join Date: May 2010 Location: e4eaf2 09-03-2013, 04:53 PM When the method "butterfly.fly" is called, it tries to activate itself before moving, which causes it to activate itself, which causes it to activate itself, etc. until eventually Alice crashes. Remove the method "butterfly.fly" that's inside itself and that should fix it. Thank you for taking the time to read this signature. This signature loves you.
 help
letsgojets
Junior Member

Status: Offline
Posts: 3
Join Date: Aug 2013
help - 09-03-2013, 08:03 PM

thanks, that worked

so now my butterfly keeps going below ground and the rabbit cant catch it.

Any thoughts
Attached Files
 ClassWork8_1ButterflyChase.a2w (341.8 KB, 8 views)

 what is it
aliirfan01
Guest

Status:
Posts: n/a
what is it - 10-10-2013, 01:35 AM

Quote:
 Originally Posted by TauTrumpsPi Just loop infinity times an if statement in a separate method that says if the butterfly goes too high, move down x meters.
i aslo have plenty of common sense ...i can't answer...

 This rant does answer your butterfly question.
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
This rant does answer your butterfly question. - 10-11-2013, 10:11 AM

Quote:
 Originally Posted by george3356 ASSIGNMENT: Make a rabbit chase a butterfly until it catches it w/ a net. I am now trying to make sure my butterfly does not go to high or to low - so high the rabbit can't reach/crashing into the ground. I know I need an if statement here, but I'm just not sure what to do with it. Any thoughts? (Again, I need to be sure the butterfly does not go to high or low using an IF/ELSE statement.)
Do not use methods with infinite loops!
Why? Well, because it can cause problems that are hard to find and because Alice tends to perform poorly when methods contain infinite loops, but more importantly there is a better alternative! The better alternative is an event and it replaces an infinite loop as follows:
1. Write the method that you want to run continuously without an infinite loop.
2. At the top of the Events section click on “create new event” and choose the “When the world starts” event.
3. Right click on the left side of the new event where the dotted pattern is, highlight the “change to” option and click on “While the world is running.”
4. Finally, left click on the pattern on the left side of your method in the “methods” section and drag the method into the “During”
Now when the movie starts so will your method and it will continue to be restarted whenever its end is reached. The running of other methods will not be affected and everyone is happy.
A few comments on events:
The event used above has three sections Begin, During and End (Programming Alice refers to it as a BDE event.) You can use one all or none of these “slots” in your event. Obviously using none of the options is useless but the others can come in handy if there are things you want to do before your During method starts or afterward in order to “clean up” when the during method ends. For the “When the world starts” event we are discussing here the “Begin” method would be called before the user interacts with the movie and the “End” event would execute as the movie was shutting down. As I stated above if you don't have any set up or clean up things that need to be done, just leave the slots blank.
There are other events that can be used to allow a method to be run only when certain conditions are met or when a variable changes. These events can be used to do things like keep an object from going too high or too low or almost any other condition you can think of and code.
Code:
```While dragon is within(subject=dragon's height / 2) of ground is true
Begin: Nothing
During: dragon.moveUp
End: Nothing```
In these situations it is better to use a general condition rather than something specific. For instance, if instead of using “dragon is within(subject=dragon's height / 2) of ground” I were to use “dragon distance above ground more... == (subject = dragon's height / 2)” the event would only be called if, when the event next checked, the dragon was EXACTLY “dragon's height/2” above the ground. If, when the condition was evaluated, the dragon was higher or lower than ½ its height above the ground, no action would be taken.

Another way to use these events is for things like making the helicopter blades spin when you want them. Using a Boolean variable as a flag to determine when to let the blades turn.
Code:
```While helicopter.spinBlades is true
Begin: helicopter.spinUp
During:  helicopter.spinning
End:  helicopter.spinDown```
In this example all three of the method “slots” are used. When helicopter.spinBlades ( which is a Boolean variable I created) becomes true, the Begin method (helicopter.spinUp) is called causing the blades to spin slowly at first and then faster and faster. When the helicopter.spinUp method completes, the event automagicly calls the “During” method (helicopter.spinning) and continues to call this method as long as the movie is running and helicopter.spinBlades is true. If at any time helicopter.spinBlades changes to false, maybe because the helicopter has landed or its engine has failed, then the “End” method is called, in this case causing the blades to slow down and stop.

One last point, if an infinite loop is used in a method the only way to call other methods is to contain them in a “Do together” block with the infinite loop. By default methods act sequentially, one after another, so Alice calls a method and then waits for it to end before going on to the next or instruction. In the case of a method with an infinite loop the method will never end because the loop will never end and so any methods or instructions following that method will not be executed. The only instructions that could be called are ones that are either in a “Do Together” block with our infinite instruction or ones that are in events become true or “fire.”
Code:
```world.my first method
Do together
print This print will execute once.
While true
print While true is always true and will never stop.
Wait 5 seconds
// End of Do together
print This print will never execute.```

Mark Henwood
mhenwood@ieee.org

 Tags alice 2, if/esle

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops     Alice Player and VR General Discussion     Questions and Comments     The Lounge

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

 Contact Us - Alice.org - Archive - Top