Alice Community  

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

Reply
 
Thread Tools Display Modes
Help with project
Old
seanr25
Junior Member
 
Status: Offline
Posts: 13
Join Date: Jan 2013
Default Help with project - 02-22-2013, 12:17 PM

I am suppose to write a hop method that makes it hop in a realistic fashion with a parameter that lets the sender of the message specify how far the animal should hop. I have made the hop method, and I am satisfied with how it looks, but I can't seem to make the right parameter to make it hop all the way to the Joey. I have created the parameter and called it "distanceToHop", and I have tried several different things to get it to work, but it only hops once. I know how to use the move method to get it to move, but it only slides across the ground to the Joey. I need it to hop "realistically" to the Joey.....

If I had any hair left, I would be ready to pull it out!!! lol Any help would be appreciated!
   
Reply With Quote
File
Old
seanr25
Junior Member
 
Status: Offline
Posts: 13
Join Date: Jan 2013
Default File - 02-22-2013, 12:19 PM

Sorry, I forgot to attach my file.
Attached Files
File Type: a2w kangaroo hop.a2w (443.5 KB, 4 views)
   
Reply With Quote
Old
bob3584
Senior Member
 
Status: Offline
Posts: 180
Join Date: Jan 2013
Location: In a Cardboard Box.
Default 02-22-2013, 08:01 PM

When do you need it done?


My avatar will always be a preview of what I am currently working on.
   
Reply With Quote
Using parameters...
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Using parameters... - 02-23-2013, 01:06 PM

Start by looking at what you have so far.
The Kangaroo is hopping 12 times using your hop method after that you calculate the distance to Joey and have the Kangaroo move forward that far.
The last instruction is why the Kangaroo is moving instead of jumping.

Your hop method needs a couple of things, look at parameters how to define and use them. Add a parameter to hop which takes the distance the kangaroo has to move in meters. Then replace the 12 (times) in your loop with the parameter. Alice will automagically throw away anything after the decimal point when a value is used in a loop in this way. Since most things are reported in meters, you probably want to change hop so that the Kangaroo will move forward 1 meter each hop.
Hint: I would not change the present move forward instruction. I would add another one just like it somewhere else in the method.

So now you have a method (hop) with a parameter that takes a number. What do you do with it?
Move the instruction calculating the distanceToHop value to before the call to Kangaroo.hop. Kangaroo.hop should now have a parameter (probably set to 1 by default) replace the value with your variable distanceToHop. Finally delete the Kangaroo move forward instruction in "My first method" and run the program.

Final note: You might want to have the kangaroo turn the face Joey before starting to hop.
   
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 ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.