Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   count the rings (http://www.alice.org/community/showthread.php?t=11540)

LauraG 07-30-2016 04:04 PM

count the rings
 
Ok, i give up. How in the hell do i get my "counter" to count the rings the user catches?
I got the text to count to ten and stop, I got the ring to fall from random positions and I got the cone to move according to where the users moves the mouse. but i couldn't get the counter to count the times the user catches the rings.
Please help me.
Pretty please with sprinkles on top.

chickentree 08-02-2016 10:09 AM

How close
 
Well, for sprinkles:)

A little background:
One problem I have seen is the use of equality between objects in Alice movies. In an environment like Alice this can result in the condition never being seen! There can be a number of reasons for this but I believe the main culprit is that Alice is an animation environment. In order for object1's distance above ground to be equal to object2's the objects must not only have exactly the same value (be equal), they must be equal [B]when Alice evaluates them[/B]. When the movie is playing Alice is continuously updating each object's position within the current movie's frame. These updates are not instantaneous nor are all objects necessarily updated at the same time. The result is that two objects can pass each other in the time between Alice's evaluation. If the distances are not [B]Exactly[/B] the same then Alice's comparison will fail!
This is why Alice has different functions like isAbove, isBelow, etc. With these functions you Alice can detect a change in conditions without looking for exact numerical values to match. In the case of the ring/cone try using the ring or cone's 'is within' function and remember that the distance is measured from wherever Alice considers the center of each object to be.

[CODE]
If ring is within 2 meters of cone
update ring count
else
do nothing
[/CODE]

This brings up a second stumbling block for many students. Where to put this test so that it will be called repeatedly during the game.
There are two basic ways to accomplish this. The most common is to place the test in a method like the world's "my first method." this works fine as long as you understand how Alice processes methods.
As in all other methods, Alice will process the instructions in "my first method" when it is called and then will continue instruction by instruction until the last instruction in the method is completed at which point the method will end.
So if our code is put into my first method without enclosing it in a loop of some kind, Alice will get to this if statement, evaluate it, take the appropriate action and continue on to the methods end. In this scenario alice will look at your comparison ONCE, at which time, since the movie is just starting, the if statement will most likely be false. After that your test is never run again.
To fix this two things are needed[LIST=1][*]A loop so that the test will be called as long as the movie is running.[*]A do together block so that the movie can do everything else it needs to.[/LIST]So calling the test over and over again might look like
[CODE]
while true
If ring is within 2 meters of cone
update ring count
else
do nothing
[/CODE]
or equivalently
[CODE]
loop infinity times
If ring is within 2 meters of cone
update ring count
else
do nothing
[/CODE]
Once Alice starts one of these looping constructs the Movie will never exit the loop and therefore will never do any instructions after the loop in the method. Nor will the method ever end, so no instructions after the method call will be processed.
So to do anything else via methods once this loop is started you need to put the loop and any other needed instructions in a do together block. As in:
[CODE]
do together
// whatever else needs to be done

// the infinite loop
while true
// the stuff to repeat over and over again
If ring is within 2 meters of cone
update ring count
else
do nothing
[/CODE]

Hopefully that will get you going!
Mark

P.S. There is a much better way to do this type of repeated testing. That is by putting the if statement into an event that runs all the time. No loop is required as the event will continue to be called as long as the movie is running (provided you use the correct event.)
[CODE]
While the world is running
Begin:
do nothing
During:
If ring is within 2 meters of cone
update ring count
else
do nothing
End:
do nothing
[/CODE]
Or
[CODE]
While the world is running
Begin:
do nothing
During:
If ring is within 2 meters of cone
update ring count
else
do nothing
End:
do nothing
[/CODE]


Mark


All times are GMT -5. The time now is 05:12 AM.

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