View Single Post
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 10-15-2013, 04:54 PM

Quote:
Originally Posted by rshoe View Post
Mark:

Thanks for your reply. I appreciate all of your help so far. I am not sure if I followed all of what you said. I was able to move the doors one at a time, but when I loop it 10 times it goes crazy. I tried for several days now and this is what I have so far. This alone is taking too long, I haven't even started on the game itself. This software is so frustrating and confusing. Whatever help you can give me I would appreciate it.

Thanks
Randy
You did pretty well considering you were using my advice
There are a couple of problems that I see. The first relativity minor problem is that you are not checking to make sure you have two different doors to swap so if the same door is selected for both doorOne and doorTwo no swapping occurs. The second problem is that you make the assumption that the doors always start out in the same location. It is true that, before any of the doors are swapped, they will be in the assumed position but after that first movement all bets are off. What is needed is a function that will take a door and return the position it is in. The result is pretty straight forward but the way that the Alice GUI works makes getting there difficult.

So the function, which I called "getPosition" takes an object, the door you want to know the position of, and gives back the dummy object at that doors position.
Code:
world.getPosition Obj door
    If doorway.is within 0.1 meters of leftDoor
        Return leftDoor
    else
        if  .......
            Return ......
        else
             Do nothing
    Return rightDoor
Note that i used the actual object doorway not the parameter door I created. This is because, as far as I can tell there is no way to directly insert parameter.is within XXX of thatThing. So to get around that I use the object to be passed in, in this case doorway, which does have the "is within" function I want. Once the function is setup just go back and replace each occurrence of the object doorway with the parameter door.
Two other things are of note here. First is that we are only testing for two conditions. This is because we know that there are only three possible positions and so if the object is not at the left dummy object and it is not at the center dummy object we know it must be at the right dummy object and so there is no need to use another if statement to test that.
The other thing of note is that I did not use "is within 0 meters of" the reason for this is simple. Setting the distance to zero might work and it might not or worse, it might work sometimes. This is a common problem working with things like animations, even though logically they should be exactly the same rounding errors can mess up the comparison, so I like a little "wiggle room" when doing these kinds of comparisons in Alice.

And now for the swap. the way I approached this is just a little different than your version. I did not use any parameters but did use 4 object local variables. One for each door (d1 & d2) and one for each door's location 9p1 & p2).
The first thing to do is to grab two different doors to swap. How can I insure the list's random item method will produce different results? I can't, its random and being random means it could pick doorway2 10 or 100 or ... times in a row. This being the case we will just have to keep asking for two doors until they are different. So when I create the door local variables I give them and initial value of doorway. Then I use a while loop to continue picking two doorways until I get two different ones.
Once we have two different doorways selected the getPosition() function can be used to get the position dummy object of each doors current location. So we have the object d1 which is some door and p1 which give the dummy object where d1 is currently positioned. And we have some other doorway d2 with its current position p2. All that is left to do is to set the point of view of d1 to p2 and set the point of view of d2 to p1 and replace the current swap method in the loop statement with this one.

I like to see what is going on when I am working on these problems so I tend to use the print instruction. In this case I would put 4 prints inside the loop, 3 to print out each door's location and one with just a period "." to produce a blank line between each call to swap.
When you select the print statement it will ask whether you are printing text or an object, for the first three select object and then pick expressions in the object list and select world.getPosition.

Code:
world.swap no parameters
    Obj d1 = doorway, Obj d2 = doorway, Obj p1 = <NONE>, Obj p2 = <NONE>
    While d1 == d2
        d1 & d2 set to random items from your door list.
    p1  set value to world.getPosition door= d1
    p2  set value to world.getPosition door= d2
    d1 set point of view to p2
    d2 set point of view to p1
Code:
world.my first method
    Loop 10 times
        world.swap
        print world.getPosition door = doorway
        print world.getPosition door = doorway2
        print world.getPosition door = doorway3
        print .


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote