Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Chapter 7 Exercise 4 Lock Combination (http://www.alice.org/community/showthread.php?t=10302)

 rshoe 10-02-2013 01:37 PM

Chapter 7 Exercise 4 Lock Combination

I was wondering if anyone has completed the lock combination in chapter seven. I could use some help looping the dial on the lock. I think there is some type of loop formula you have to use to set the combination. I have looked at some examples of locks and they do not show how to loop the lock or they manually set the lock. If anyone has done this I would appreciate any help.

Thank you,
Randy

 chickentree 10-08-2013 11:15 AM

[QUOTE=rshoe;53516]I was wondering if anyone has completed the lock combination in chapter seven. I could use some help looping the dial on the lock. I think there is some type of loop formula you have to use to set the combination. I have looked at some examples of locks and they do not show how to loop the lock or they manually set the lock. If anyone has done this I would appreciate any help.

Thank you,
Randy[/QUOTE]

Do you have the 4 class level methods working?

 rshoe 10-08-2013 12:06 PM

Lock combo

1 Attachment(s)
Mark:

I think I found the solution but I not sure. I have uploaded the code. Let me know what you think.

Also have you worked with the Monty game Project in chapter 9. I have looked all over the web to find some clue on how to even start coding the game. If you have any type of solution or where I can find out more information please let me know.

Thanks,
Randy

 chickentree 10-08-2013 06:23 PM

[QUOTE=rshoe;53525]Mark:

I think I found the solution but I not sure. I have uploaded the code. Let me know what you think.

Also have you worked with the Monty game Project in chapter 9. I have looked all over the web to find some clue on how to even start coding the game. If you have any type of solution or where I can find out more information please let me know.

Thanks,
Randy[/QUOTE]

Hi Randy
Lets start at the beginning.
1) It works that's great!
2) I would get rid of the do together blocks (move the instructions out of them and delete them.) While the lock seems to work as is, what you are telling Alice to do is to turn one revolution left and 9 numbers right at the same time. The other loop is simular except you are making 3 revs instead of one and I believe the the last should be rightOne not leftOne.
3) You don't need the loop for a count of 1. Looping once is the same as just calling the instruction.
4) Personal opinion: I would add at least a short wait between the revolution and moving to the number. I would probably also make the left/right one a little faster.

Over all I think you did an excellent job.
Mark

 chickentree 10-08-2013 06:32 PM

Monty

[QUOTE=rshoe;53525]Mark:

I think I found the solution but I not sure. I have uploaded the code. Let me know what you think.

Also have you worked with the Monty game Project in chapter 9. I have looked all over the web to find some clue on how to even start coding the game. If you have any type of solution or where I can find out more information please let me know.

Thanks,
Randy[/QUOTE]

Hi Randy,
Looking at the Monty game I need to know where you are having a problem. It seems pretty straight forward especially as you are not required to keep track of the results in Alice. Just run Alice and record the results. If you name the door objects something like carDoor, monkey1Door, monkey2Door and then attache the prize objects to each door (remember the vehicle method?) then when the door moves so will the "prize" and so the swap should be easy.

Mark

 rshoe 10-08-2013 08:15 PM

The Monty Game

Mark:

Thanks for the information on the combo lock. I will look at it and make the changes..

As far as the Monty Game - I have made a list containing the three doors, and I set the car and the two monkeys to the doors as vehicle. I have made a method called swap with two doors as parameters. I'm not sure how to swap the doors and move them 2.5 meters in opposite direction with out moving them off the screen. I am having trouble starting this.

The book reads: "Use a method called swap that takes two doors as parameters. Swap the two doors by having them move 2.5 meters in opposite directions. Important: Two doors should swap only if they are different ( a door cannot swap places with itself).

Thank you for all your help.
Randy

 chickentree 10-11-2013 12:18 PM

Setup and using dummies.

[QUOTE=rshoe;53531]Mark:

Thanks for the information on the combo lock. I will look at it and make the changes..

As far as the Monty Game - I have made a list containing the three doors, and I set the car and the two monkeys to the doors as vehicle. I have made a method called swap with two doors as parameters. I'm not sure how to swap the doors and move them 2.5 meters in opposite direction with out moving them off the screen. I am having trouble starting this.

The book reads: "Use a method called swap that takes two doors as parameters. Swap the two doors by having them move 2.5 meters in opposite directions. Important: Two doors should swap only if they are different ( a door cannot swap places with itself).

Thank you for all your help.
Randy[/QUOTE]

Sorry for the delay in answering.
The short answer is you don't because the 2.5 meters will only work if the doors are (I am assuming) next to each other and if they are aligned exactly. This means they are not on an angle and one is not in front or behind another.
As in so many cases with Alice, setup is 80% of the exercise.
So the situation is as follows:
You have three doors, you want them spaced evenly and you want to know how far away each door is from the others. Lets look at one way to do this:
You already have your doors so this is what I would do:[LIST=1][*]Pick a door to you want to be on the far left and move it to the center of the stage.[*]Right click on the object in the list to the left of the stage, go to methods and select "turn to face" and pick the camera.[*]Using the same "right click and pick a method" procedure move the door back far enough so that all three doors will fit in the scene.[*] Still using the method above move the door to the left side of the scene.[/LIST]You have one door where you want it for the start of the movie. I said to use methods instead of moving the object with the mouse so that the object's orientation to the camera does not change. And we started in the middle of the scene so that the door would be straight on to the camera. If the door were on the left and instructed to turn to face the camera, it would turn to the right some amount and the rest of our work would be slightly off.[LIST=1][*]Make sure the Door you just positioned is selected.[*]Drop a dummy object at the selected object. If you don't see the "Drop a dummy at the selected object" ensure you are in the "Add Objects" view and click the "more controls" button on the right under the icons.[*]In the Object tree on the left click on the + sign to the left of Dummy[*]Right click on the dummy object and name it left door.[*]Select the right door[*]Right click on the object tree, hover over methods and select "set point of view to" and pick the left door.[*]Using the same procedure select "Move Right" and move the right door to the right of the screen. Keep track of how far you move it! and remember you can always use the undo button.[*]Drop a dummy at the right door and name it right door.[*]Follow the same procedure to orient and move the center door and move it 1/2 the distance you moved the right door.[*]Again drop a dummy object and name it "center door"[/LIST]You should now have 3 doors and more importantly you know how far to move a door so that it is in the place of another door. You should also be able to see that swapping one of the outside doors (right or left) with the center door will involve each door moving some distance while swapping the end doors will require each door to move twice that distance. If the door goes off the stage it is because it was moved in the wrong direction. In other words to swap the door on the left with the center door, we move the left door to the right and the center door the same amount to the left. Neither should leave the stage.

But wait there's more! You can now move the doors around without worrying about moving how far or in what direction or even which door is moving. How? By using the dummy objects! [LIST][*]Pick two dummy objects.[*]Find the doors with the same position as these dummy objects.[*]Set the "point of view" of each door to the other dummy object.[/LIST]Finding the doors with the same position as the selected dummy objects involves using the list methods, since you already said your doors were in a list.

Hope this helps
Mark

 rshoe 10-14-2013 01:41 PM

Monty Game

1 Attachment(s)
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

 chickentree 10-15-2013 05:54 PM

[QUOTE=rshoe;53555]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[/QUOTE]

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
[/CODE]

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]

[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 .
[/CODE]

 rshoe 10-15-2013 09:22 PM

Monty update

1 Attachment(s)
Mark:

Thanks for your update. I looked at your new code and tried to follow along. I was unable to put d1 & d2 set into random items in the While loop. I have attached the file. The only way I was able to put the random items in was by using set value to. If there is another way please let me know.