Alice Community Creating a spinner

 Creating a spinner
 john316 Junior Member   Status: Offline Posts: 10 Join Date: Apr 2015 Creating a spinner - 05-04-2015, 06:52 PM The spinner object is already in Alice. How do I make a character move that many spaces for which ever number the arrow lands on (using random number). I tried using object variables and and setting it to each number on the spinner but it doesn't work. I'm completely clueless.
 RavenOfCode Senior Member     Status: Offline Posts: 409 Join Date: Oct 2013 Location: Northern Virginia 05-05-2015, 02:42 PM Is this for school? Just wana make sure I can post coding changes... Stuff + Other Stuff + Different Other Stuff = Things :) My best Alice game: Clash of the Cubes (an arena fighting game): http://www.alice.org/community/showthread.php?t=10738&highlight=game
 john316 Junior Member   Status: Offline Posts: 10 Join Date: Apr 2015 05-05-2015, 03:10 PM It's for a project, I'm completed the rest of the project , but this is the only issue I'm having
 RavenOfCode Senior Member     Status: Offline Posts: 409 Join Date: Oct 2013 Location: Northern Virginia 05-05-2015, 05:22 PM Ok, thanks for letting me know that. From what I understand you are turning the spinner then checking the number, try it the other way around. Start by calculating the number first, then turn the spinner according to the number calculated. Hope this helps for you out. Best, RavenOfCode Stuff + Other Stuff + Different Other Stuff = Things :) My best Alice game: Clash of the Cubes (an arena fighting game): http://www.alice.org/community/showthread.php?t=10738&highlight=game Last edited by RavenOfCode; 05-05-2015 at 06:32 PM.
 john316 Junior Member   Status: Offline Posts: 10 Join Date: Apr 2015 05-06-2015, 09:54 AM That's the problem I'm completely clueless on how to do that. There is no ''When'' method for example, when arrow pointer is at or = to object parameter , move this many spaces. I'll still try to figure it out.
RavenOfCode
Senior Member

Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
05-06-2015, 07:49 PM

Quote:
 Originally Posted by john316 That's the problem I'm completely clueless on how to do that. There is no ''When'' method for example, when arrow pointer is at or = to object parameter , move this many spaces. I'll still try to figure it out.
Use something like:

SpinnerV (a number variable) set value to random number (how every many spinner sections there are)

Spinner turn left .25 (or whatever number works) * spinnerV

This is a basic outline for what to do... all the exact amounts ill let you figure out.

Stuff + Other Stuff + Different Other Stuff = Things :)

My best Alice game:

Clash of the Cubes (an arena fighting game):

chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
05-08-2015, 05:35 PM

Quote:
 Originally Posted by john316 The spinner object is already in Alice. How do I make a character move that many spaces for which ever number the arrow lands on (using random number). I tried using object variables and and setting it to each number on the spinner but it doesn't work. I'm completely clueless.
There are two ways I've found that will do what you want. By far the easiest is using poses the work is all "up front" i.e. done in the design not during execution but it works.
1. Select the spinner and in the properties panel (Lower left of Alice) click on "Create Pose" use "initialPose" for the name.
2. Repeat the step above but use "onePose" for the name (I am assuming the spinner is initially pointing at one.)
3. I'm assuming you are using the spinner with 20 divisions. So movement between the segments is 1/20th of a rotation, or 0.05 revolutions.
4. In the Alice IDE right click on the spinner's Arrow ( the whole arrow not just the head.) Then select Methods-Turn-Left and enter 0.05 for the amount.
5. Now select the whole spinner.
6. In the "Properties" tab at the left, click the "Capture Pose" button and give the pose a name. I used the name of the segment and added "Pose" on the end. As in "twoPose", this will help you if you end up using the section name in your program.
7. Repeat steps 3 through 6 until you have a pose for each spinner position.

To simplify things further you can create an array variable containing the poses but remember the array indexes start at 0 so if you wanted the spinner to go to 6 you would use an index of 5, or more generally index = spinValue-1.

The only problem I have found with this approach is that in going from one pose to another the spinner will take the shortest path, sometimes turing right and other times turning left. To get around this you could identify cases where the spinner would go the wrong way and take two steps to get to the desired value. The first would be a segment between the initial and final values in the direction you want the Arrow to turn. This would ensure the Arrow travels in the right direction.

Mark

Mark Henwood
mhenwood@ieee.org

Last edited by chickentree; 05-08-2015 at 05:38 PM. Reason: minor correction

john316
Junior Member

Status: Offline
Posts: 10
Join Date: Apr 2015
05-09-2015, 07:47 PM

I tried doing the poses, but the player isn't moving the respective places. Attached is what I have done so far.

Quote:
 Originally Posted by chickentree There are two ways I've found that will do what you want. By far the easiest is using poses the work is all "up front" i.e. done in the design not during execution but it works.Select the spinner and in the properties panel (Lower left of Alice) click on "Create Pose" use "initialPose" for the name. Repeat the step above but use "onePose" for the name (I am assuming the spinner is initially pointing at one.) I'm assuming you are using the spinner with 20 divisions. So movement between the segments is 1/20th of a rotation, or 0.05 revolutions. In the Alice IDE right click on the spinner's Arrow ( the whole arrow not just the head.) Then select Methods-Turn-Left and enter 0.05 for the amount. Now select the whole spinner. In the "Properties" tab at the left, click the "Capture Pose" button and give the pose a name. I used the name of the segment and added "Pose" on the end. As in "twoPose", this will help you if you end up using the section name in your program. Repeat steps 3 through 6 until you have a pose for each spinner position. To simplify things further you can create an array variable containing the poses but remember the array indexes start at 0 so if you wanted the spinner to go to 6 you would use an index of 5, or more generally index = spinValue-1. The only problem I have found with this approach is that in going from one pose to another the spinner will take the shortest path, sometimes turing right and other times turning left. To get around this you could identify cases where the spinner would go the wrong way and take two steps to get to the desired value. The first would be a segment between the initial and final values in the direction you want the Arrow to turn. This would ensure the Arrow travels in the right direction. Mark
Attached Files
 test.a2w (1.03 MB, 7 views)

RavenOfCode
Senior Member

Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
05-10-2015, 08:33 AM

My way works...

This took me about 3 mins to make...

Calculate the spinner variable first then turn it accordingly...
Attached Files
 spinner.a2w (1.16 MB, 2 views)

Stuff + Other Stuff + Different Other Stuff = Things :)

My best Alice game:

Clash of the Cubes (an arena fighting game):

chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
05-10-2015, 03:10 PM

Quote:
 Originally Posted by RavenOfCode My way works... This took me about 3 mins to make... Following what I had said Calculate the spinner variable first then turn it accordingly...
Yep, it is better than either of mine. I hadn't thought of using just one initial position but it is a lot nicer solution. But the problem with the test.a2w John316 submitted shows a couple of other problems.
John316, you should understand that making the spinner spin is just appearance, smoke and mirrors, eye candy for the program. It is a way to show the user what the result of the spin was. Alice seems to let you compare poses but it doesn't work correctly and even if it did you are comparing two poses without regard to where the arrow is actually pointing. Your "if" statements will do the "if" part every time regardless of the pointers location.
As RavenOfCode said in a previous post, you want to use a variable to hold the value returned from "random number" (Raven used world.spins in the code he posted.) You then use the value of world.spins to both position the arrow on the spinner and to move the character forward.
One more thing, the "Boy" you are using has a walk method. If you call Boy.walk(world.spins) the boy should walk that number of steps.

Mark

Mark Henwood
mhenwood@ieee.org

 Tags spinner

 Thread Tools Display Modes Hybrid 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