Alice Community  

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

Reply
 
Thread Tools Display Modes
Creating a spinner
Old
john316
Junior Member
 
Status: Offline
Posts: 10
Join Date: Apr 2015
Unhappy 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.
   
Reply With Quote
Old
RavenOfCode
Senior Member
 
RavenOfCode's Avatar
 
Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
Default 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
   
Reply With Quote
Old
john316
Junior Member
 
Status: Offline
Posts: 10
Join Date: Apr 2015
Default 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
   
Reply With Quote
Old
RavenOfCode
Senior Member
 
RavenOfCode's Avatar
 
Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
Default 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.
   
Reply With Quote
Old
john316
Junior Member
 
Status: Offline
Posts: 10
Join Date: Apr 2015
Default 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.
   
Reply With Quote
Old
RavenOfCode
Senior Member
 
RavenOfCode's Avatar
 
Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
Default 05-06-2015, 07:49 PM

Quote:
Originally Posted by john316 View Post
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):
http://www.alice.org/community/showthread.php?t=10738&highlight=game
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 05-08-2015, 05:35 PM

Quote:
Originally Posted by john316 View Post
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
   
Reply With Quote
Old
john316
Junior Member
 
Status: Offline
Posts: 10
Join Date: Apr 2015
Unhappy 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 View Post
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
Attached Files
File Type: a2w test.a2w (1.03 MB, 7 views)
   
Reply With Quote
Old
RavenOfCode
Senior Member
 
RavenOfCode's Avatar
 
Status: Offline
Posts: 409
Join Date: Oct 2013
Location: Northern Virginia
Default 05-10-2015, 08:33 AM

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...
Attached Files
File Type: a2w 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):
http://www.alice.org/community/showthread.php?t=10738&highlight=game
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 05-10-2015, 03:10 PM

Quote:
Originally Posted by RavenOfCode View Post
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
   
Reply With Quote
Reply

Tags
spinner

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.