Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   How to use the random function (http://www.alice.org/community/showthread.php?t=4870)

lstricland 08-14-2010 04:13 PM

How to use the random function
 
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:

[B]Skater turn to face [random cone]

Move direction to [random cone]

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


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.

debussybunny563 08-14-2010 05:20 PM

[SIZE="2"]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:

[B]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[/B]

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.[/SIZE]

lstricland 08-14-2010 05: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=debussybunny563;24053][SIZE="2"]
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.[/SIZE][/QUOTE]

lstricland 08-14-2010 06:12 PM

1 Attachment(s)
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...:D

I will still work on it as much as I can but I'd appreciate any help. Thank you so much!

debussybunny563 08-14-2010 06:46 PM

Finished
 
1 Attachment(s)
[SIZE="2"]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![/SIZE]

lstricland 08-14-2010 07:11 PM

1 Attachment(s)
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=debussybunny563;24058][SIZE="2"]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![/SIZE][/QUOTE]


All times are GMT -5. The time now is 04:01 AM.

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