Alice Community  

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

Reply
 
Thread Tools Display Modes
Difficulty with random number generation
Old
JasonMichael
Junior Member
 
Status: Offline
Posts: 13
Join Date: Jan 2014
Location: Ennis, TX
Default Difficulty with random number generation - 04-27-2014, 06:11 PM

Hey folks! I just finished Assignment 4 with the boomboom method. I could not figure out how to create a method called distance that randomly generated numbers in feet, instead of meters. Since it was only meters that I could get to work, I used randomization between 1 and 2 so the character would not go off screen during his jumps.

My question is, how do we set it to feet instead of meters, or can we randomize non-integer meters like randomize from .5 to 2.3 meters with the random numbers rounded off to the nearest tenth? Either one of these solutions would allow for a more varied jump distance while remaining on the screen.
   
Reply With Quote
Old
xCROv
Guest
 
Status:
Posts: n/a
Default 04-28-2014, 01:37 AM

Well. A meter is 3 feet; you could do a simple math problem if you wanted it in feet. I have not read that assignment so I'm not sure on the specifics for it but you can make an object walk as far or as short as you want.

Last edited by xCROv; 04-28-2014 at 01:41 AM.
   
Reply With Quote
Try this
Old
jrrTolkien
Senior Member
 
jrrTolkien's Avatar
 
Status: Offline
Posts: 166
Join Date: Feb 2014
Location: Middle-Earth (Merrimack, NH)
Cool Try this - 04-28-2014, 08:33 AM

1 meter is about equal to 3.28 feet. Create a variable, then do set value to a random integer (found in the world.functions tab,) tell it to instantly multiply it by 3.28 (or just 3.3 if you're lazy ), and you'll have it in feet. If you want to see it whenever it changes, you can right-click your variable, and select "watch this variable" and it will show up when you select the play button. If you want to avoid all this extra work, though, you can simply just work in meters.

-jrr
Attached Files
File Type: a2w random feet world.a2w (167.5 KB, 0 views)
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 04-28-2014, 09:05 AM

Quote:
Originally Posted by JasonMichael View Post
Hey folks! I just finished Assignment 4 with the boomboom method. I could not figure out how to create a method called distance that randomly generated numbers in feet, instead of meters. Since it was only meters that I could get to work, I used randomization between 1 and 2 so the character would not go off screen during his jumps.

My question is, how do we set it to feet instead of meters, or can we randomize non-integer meters like randomize from .5 to 2.3 meters with the random numbers rounded off to the nearest tenth? Either one of these solutions would allow for a more varied jump distance while remaining on the screen.
First, there is no way I know of to change Alice to use feet automagically. The world, functions and methods are all predicated on the metric system.
Converting value given in feet to meters is however easy.
  1. Create a function called feet2meters that returns a number
  2. Add a numeric parameter called lenInFeet
  3. Add a variable called conversionFactor
  4. Set conversion factor to 0.3048
  5. return lenInFeet * conversionFactor

If you click the on the more ... in the random number function you will find that you can set 3 values a minimum, a maximum, and integerOnly. The min and max can be set to any value as long as min<max and as long as the integerOnly is not set or false, the function will return values between min and max. Note that due to the way it works random number can return the min value but will never return the max value.

I am not sure why you want to round to 10ths, I usually do this for value I want to display as 3d text. To accomplish this write another function that takes in a number and returns the desired value. For tenths:
  1. multiply the given number by 10
  2. round the number using the round function. This drops the decimal part.
  3. divide by 10 to change to tenths.

As an exercise you could try and make this function return any number of decimal places. (hint: Add a parameter for the number of places and use the
a raised to the b power function


Mark Henwood
mhenwood@ieee.org
   
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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.