Alice Community  

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

Reply
 
Thread Tools Display Modes
How to use the random function
Old
lstricland
Guest
 
Status:
Posts: n/a
Default How to use the random function - 08-14-2010, 03:13 PM

I was here yesterday and was able to get some good help...thank you!!

I am back again to ask help for the last problem (out of the 5) that I'm working on right now. This is due tomorrow night and I'm really desperate to get help.

The problem is to let all 4 skaters to skate around each of the 4 cones. However, the cones will be randomly chosen and the hint was to use the "random number" function. Here's an idea:

Skater turn to face [random cone]

Move direction to [random cone]

Turn left 1 revolution as seen by=[random cone]



I tried to make a world function (randomCone) where each cone represents a number. For example:

randomCone set value as [random number minimum=1 maximum=4

If randomCone == 1
Return = Cone

If randomCone == 2
Return = Cone2

etc...

When I tried to call this function, I obviously cannot make it to work.

Here are my questions:

1. How can I make each skater face to a random cone, move forward to THAT cone and turn around THAT same cone?

2. I'm not sure what I'm doing with the world function (object) that I created. I just saw a document tutorial online that I tried to follow.


Again, none of these topics were discussed in our class, nor was this covered in the "Learning to Program with Alice Second Edition". I will see if I can attach my world on here since I can't even make any sense out of my work.

Thank you so much for any help you can give. Trust me, I am doing everything on my end. If this was discussed in my class, I wouldn't have any problem doing it.
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Post 08-14-2010, 04:20 PM

I'll wait till you upload the world, and then I'll see what I can do with it.

You don't have to use the random number function, since it's not necessary, but there is a way to do it with that.

You'll probably have to make a numeric variable, and assign each cone to a certain number of the variable.

It'll probably look something like this:

1. world.number set value to [random number min=1 max=4]

2. If world.number=1
world.skatetocone1

Else
If world.number=2
world.skatetocone2

Else
If world.number=3
world.skatetocone3

Else
If world.number=4
world.skatetocone4

Else
Do nothing


Basically, at the beginning it sets the number variable to a random number, and then the If/Else statements nested within each other check to see which skating method it should do (to which cone) based on the random number function.

You don't actually have to have a separate skate method for each cone (you can use a parameter and use a single, all-encompassing method), but I don't know how far you are in your class, so you can stick to 4 different methods for now.

If you want, I can make an example of the parameter.

EDIT: Wait a minute, I misread. Four skaters and four cones?
To clarify, do the skaters skate to a different cone at the same time, or do they do it in a certain order?
From what it sounds like, each of the skaters goes in order, and each one skates to each of the four cones, but in a random order.
Please tell me exactly what the prompt is.

Last edited by debussybunny563; 08-14-2010 at 04:30 PM.
   
Reply With Quote
Old
lstricland
Guest
 
Status:
Posts: n/a
Default 08-14-2010, 04:40 PM

The skaters will skate around each cones one after another, but the cones will be randomly selected. The instruction said, "each skater should skate around four cones prior to returning to their start position".

I will your suggestion and post the world on here in a little bit.

Quote:
Originally Posted by debussybunny563 View Post

EDIT: Wait a minute, I misread. Four skaters and four cones?
To clarify, do the skaters skate to a different cone at the same time, or do they do it in a certain order?
From what it sounds like, each of the skaters goes in order, and each one skates to each of the four cones, but in a random order.
Please tell me exactly what the prompt is.
   
Reply With Quote
Old
lstricland
Guest
 
Status:
Posts: n/a
Default 08-14-2010, 05:12 PM

Okay, here's what I've done so far. I created a world method where I've assigned each number (1-4) to each cone (skateToCone method). I'm attaching the world so you can see what I mean. I just did it for the first skater and I tried to call the method and it didn't work. I know I'm missing something and I have no clue. Please don't laugh at my work...

I will still work on it as much as I can but I'd appreciate any help. Thank you so much!
Attached Files
File Type: a2w skaters.a2w (4.84 MB, 8 views)
   
Reply With Quote
Finished
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Arrow Finished - 08-14-2010, 05:46 PM

Fixed everything for all of the skaters.

As you'll see, there are parameters for many of the events.
Parameters help when you need to have multiple objects do more or less the same thing, which is perfect in this case.
Look through the coding a bit, and tell me if you have any questions, but try to spend at least a little time first trying to figure it out by yourself; you learn better that way.

While I do enjoy helping people like you solve your problems, note that while you might think it's nice now, it's more helpful in the future if you learn what you're doing on your own and don't have go be dependent on others.
Good luck in your class!

I realize you needed some help, so that's what I'm here for!
Attached Files
File Type: a2w skaters.a2w (4.93 MB, 13 views)
   
Reply With Quote
Old
lstricland
Guest
 
Status:
Posts: n/a
Default 08-14-2010, 06:11 PM

Thank you so much for all your help. I tried to add some more things to it. Instead of going to a "dummy cube" at the center before going going to each cones, I deleted those statements and just started off from where the skater/s' starting point.

How come the "chooseCone" method is not responding when I call it? I am not quite sure what I am missing. Thank you so much again. Yes, I am very willing to learn. I should've taken this on a regular semester and not on a summer. I've only used Alice for only 3 weeks. I like it a lot...it just takes a while to get used to.

Anyway, I'm attaching the world again. If the "chooseCone" method will respond, I will just have to add some details to it and it's done!

Quote:
Originally Posted by debussybunny563 View Post
Fixed everything for all of the skaters.

As you'll see, there are parameters for many of the events.
Parameters help when you need to have multiple objects do more or less the same thing, which is perfect in this case.
Look through the coding a bit, and tell me if you have any questions, but try to spend at least a little time first trying to figure it out by yourself; you learn better that way.

While I do enjoy helping people like you solve your problems, note that while you might think it's nice now, it's more helpful in the future if you learn what you're doing on your own and don't have go be dependent on others.
Good luck in your class!

I realize you needed some help, so that's what I'm here for!
Attached Files
File Type: a2w skaters.a2w (5.09 MB, 11 views)

Last edited by lstricland; 08-14-2010 at 06:15 PM.
   
Reply With Quote
Reply

Tags
random function

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.