View Single Post
Super Moderator
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 05-08-2015, 05:35 PM

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 Henwood

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