PDA

View Full Version : Chapter 7 Exercise 4 Lock Combination


rshoe
10-02-2013, 01:37 PM
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
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

Do you have the 4 class level methods working?
Please attach your movie so I can see where you are.

rshoe
10-08-2013, 12:06 PM
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
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

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
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

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
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
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

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:

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.

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.

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"

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!

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.

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
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
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.

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.


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



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 .

rshoe
10-15-2013, 09:22 PM
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.

Thank you for your time.
Randy

chickentree
10-16-2013, 08:20 AM
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.

Thank you for your time.
Randy

Hi Randy,
The only problem with your code is that only the first two instructions should be in the while loop. Do you see why?

Mark

rshoe
10-16-2013, 11:27 AM
Mark:

I guess I am missing something here. Are you saying I should only have the first two codes in the While loop which are:

p1 set value to world.getPosition door= d1
p2 set value to world.getPosition door= d2

If this is the case the code does nothing. If I add the two additional codes you posted:
d1 set point of view to p2
d2 set point of view to p1

The code still does nothing. I am totally lost.
Thanks for your help.
Randy:confused:

chickentree
10-16-2013, 12:21 PM
Mark:

I guess I am missing something here. Are you saying I should only have the first two codes in the While loop which are:

p1 set value to world.getPosition door= d1
p2 set value to world.getPosition door= d2

If this is the case the code does nothing. If I add the two additional codes you posted:
d1 set point of view to p2
d2 set point of view to p1

The code still does nothing. I am totally lost.
Thanks for your help.
Randy:confused:


No I am saying you should only have:

d1 set value to random item from world.doors
d2 set value to random item from world.doors

in the while block all the other instructions should be moved below the while block. If you look at the example I sent these two instructions are indented underneath the while block and the others are at the same level as the while.

What I am more concerned with is you being "lost" it does no good to complete the assignment if you don't understand how it works. It is the concepts that are important not the answer. Can you explain to me the way the program works so far and what is unclear? I would rather help you to understand what is going on then to just provide answers.

Mark

rshoe
10-16-2013, 08:45 PM
Mark:
I want to thank you for all your help. I am sorry I did not understand your instructions for the code underneath the while statement. I did move the code and it still did not work. I have run out of time on this project and I will have to use an old version where two doors move once and try to figure out how to code the rest of the problem. I am behind on three other projects in chapter 10 on which I am confused. Unfortunately I am not graded on concepts but on if the program works and if I have the code in the right order. You have provided me with more information than any other person I have communicated with. I have even tried to hire a tutor but to no avail - either people do not know how to use the program or they do not want to take the time to help.
I have read the all the chapters from one to chapter 10 and understood most of the information in them. The last three chaptersí assignments seem to be more complicated than the chapters themselves. Some codes that I do see from other people who do some of the assignments do not follow the instructions in the book and the code seems more confusing to me.
I think what makes the program so frustrating is not only is it buggy, it is hard to follow the graphical coding. Maybe this is just me. I think for this reason that my college is not going to use it next year. The code is hard to follow sometimes and when you only have limited amount of time to read and work with the exercises it makes it even harder.
So again, I thank you for your time. If you have any other suggestion please let me know.
Randy
:(

chickentree
10-19-2013, 08:00 AM
Mark:
I want to thank you for all your help. I am sorry I did not understand your instructions for the code underneath the while statement. I did move the code and it still did not work. I have run out of time on this project and I will have to use an old version where two doors move once and try to figure out how to code the rest of the problem. I am behind on three other projects in chapter 10 on which I am confused. Unfortunately I am not graded on concepts but on if the program works and if I have the code in the right order. You have provided me with more information than any other person I have communicated with. I have even tried to hire a tutor but to no avail - either people do not know how to use the program or they do not want to take the time to help.
I have read the all the chapters from one to chapter 10 and understood most of the information in them. The last three chaptersí assignments seem to be more complicated than the chapters themselves. Some codes that I do see from other people who do some of the assignments do not follow the instructions in the book and the code seems more confusing to me.
I think what makes the program so frustrating is not only is it buggy, it is hard to follow the graphical coding. Maybe this is just me. I think for this reason that my college is not going to use it next year. The code is hard to follow sometimes and when you only have limited amount of time to read and work with the exercises it makes it even harder.
So again, I thank you for your time. If you have any other suggestion please let me know.
Randy
:(
One last shoot:
In getPosition change doorway to door in the second if statement.

rshoe
10-22-2013, 11:55 PM
Mark:

Thank you for your reply. Unfortunately I had to turn the project in. Now I am working on Kick a Field Goal game from chapter 10. I know you have to use a variable when asking a question for angle and velocity, but I do not know how to take those variables and use the math code the book suggested. The code is used to move the football toward the field goal. If you have any suggestions please let me know.

Thank you again,
Randy
:confused:

chickentree
10-23-2013, 03:35 PM
Mark:

Thank you for your reply. Unfortunately I had to turn the project in. Now I am working on Kick a Field Goal game from chapter 10. I know you have to use a variable when asking a question for angle and velocity, but I do not know how to take those variables and use the math code the book suggested. The code is used to move the football toward the field goal. If you have any suggestions please let me know.

Thank you again,
Randy
:confused:

Hi Randy,
I need you to start another thread for this (should have done that last time) and could you include the movie so far so I can see where you are at?

Mark

rshoe
10-27-2013, 08:21 PM
Mark:

I put another thread out on the form for the new game. The title is Kick a Field Goal Game.

Thanks for all your help.
Randy