Alice Community  

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

Reply
 
Thread Tools Display Modes
count the rings
Old
LauraG
Junior Member
 
Status: Offline
Posts: 7
Join Date: Jul 2016
Default count the rings - 07-30-2016, 04:04 PM

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.
   
Reply With Quote
How close
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 212
Join Date: Dec 2012
Location: Frosno, Ca
Default How close - 08-02-2016, 10:09 AM

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 when Alice evaluates them. 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 Exactly 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
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
  1. A loop so that the test will be called as long as the movie is running.
  2. A do together block so that the movie can do everything else it needs to.
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
or equivalently
Code:
loop infinity times
    If ring is within 2 meters of cone 
        update ring count
    else
        do nothing
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
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
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

Mark


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote
Reply

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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.