PDA

View Full Version : How to make a Clicked Object = A variable


ctpmn
09-22-2006, 02:14 PM
I would really like to be able to click on an object and store it as a variable then be able to click on another object and store that as a variable. Then be able to run my Method. I tried storing the object as a parameter, but i cannot get it to store 2 parameters before running the script. Please help, me and like 7 other people canot figure this out. Any help would be greatly appreciated.

Mr Nemo
09-22-2006, 08:36 PM
I think this is what you wanted...

ctpmn
09-22-2006, 10:13 PM
Thanks for the response, but what I need is to save the mouse click as a variable or parameter like you have, but then I need to be able to save another mouse click as another variable/parameter. I want to be able to click on one object then another and then i want the program to be able to use those variables to run a program. Specifically I want the taller of the 2 objects to turn 1 revolution. My Logic thus far was this. It doesn't work at all though. I belive it will once i can store a 2 clicked on object as a variables

If
"object1" is taller than "object2"
"object1" turn left 1 revoultion
Else
If
"object2" is taller than "object1"
"object2" turn left 1 revoultion
Else
Do Together
"object2" turn left 1 revolution
"object1" turn left 1 revolution
The Problem is setting the objects equal to the objects i choose

Mr Nemo
09-22-2006, 10:17 PM
You should try constructing a list or an array and adding the objects that the user clicks on to the list. Then when the user hits a key, Alice performs diagnostics on the list to determine which is taller. I'll do some code work, but I might not get it up 'til tomorrow afternoon.:)

Mr Nemo
09-23-2006, 04:00 PM
I got the basic code structure, worked out, cost me half an hour. Take a look at the code so you know what to do in the future.
p.s. I'd love to see what you're working on.

lanceA
09-23-2006, 04:06 PM
When he offers, "...me and like 7 other people canot figure this out" dare I say it's somebodies HOMEWORK. :rolleyes:

Mr Nemo
09-23-2006, 06:39 PM
Dare I say that that little factoid is completely irrelevant. You are looking from behind clouded glasses my friend, as you are a teacher yourself. I, on the other hand, am a student, and view this as nothing more than student helping student, which I dare say is not a crime even your book. I sure hope you allow study groups in your class.

lanceA
09-23-2006, 07:38 PM
When I instruct my students NOT to use other's code, then it is wrong for you to show them the code to do it. How can they NOT use that code?

Someone posted code on here a few days ago and infatically stated "Do NOT copy this code !!!! " .................wanna take a bet on whether or not it was copied?

We can point students in the proper direction but I do not believe we need to do their assignments for them.

Good luck with your programming projects. You have shown that you have a good grasp of ALICE.

l

ctpmn
09-25-2006, 12:15 AM
Okay, so I really REALLY appreciate the help your trying to give, but I don't really see what you did. Firstly I wasn't aware you could put an array in Alice, secondly i cannot find any of your code that will do anything but print the object clicked on. Mabye I'm missing something but all I see in that code is the method to print which object you click on.
If there is something that I'm not seeing, which there must be, considering you spent a half hour on this. Not meaning to be all noobish, but I cant see where the rest of your time went.
And for the record it IS homework, and the teacher just gave up on it and said that we should make yes or no boxes for each possible scenario, but thats just rediculous. So, mabye it's impossible with Alice. Personally I'd just like to be able to assign a variable to an object clicked on then do another, you think it'd be easy.

ctpmn
09-25-2006, 12:19 AM
It seems to be the same as the first file, mabye you uploaded the wrong one?? HERES HOPING!!!!! lol. Thanks for all the work you put into helping a "Junior Member" like me. ;)

DrJim
09-25-2006, 03:00 PM
An alarm bell went off when you said "the logic doesn't seem to work, but ..." or something similar.

The attached world basically duplicates the logic, without mouse selection, and demonstrates a potential problem. Object1 and Object2 have to be assigned manually in world.myfirst method. If you test the logic, you'll see it works fine for the spheres (a sphere's height, width and depth are, by definition, the same). It also appears to work for the Arch (half torus) and Ball and Ball2 who appear (and are) "taller."

When you try it with Ball1 and the Arch, however, Ball1 spins instead of the Arch, even though the Arch appears "taller." Oops!:eek:

If you have the Arch "stand up" and move it's position so you can see all of it, the cause of the problem becomes obvious - the Arch considers the vertical (tall) direction to be in the plane of the cross section of the torus, which is, in fact, smaller than the diameter of Ball 1. If you resize either the Arch or Ball 1 with this viewing orientation, you will see that the logic is working correctly per the objects' definitions of "tall".

Question - Can this definition be changed?

ctpmn
09-25-2006, 03:11 PM
What i need is something that will set the varible = to the object clicked on, THEN set ANOTHER variable to the next object clicked on and THEN run the method. If you have any other ideas though make a new one and try it.

Mr Nemo
09-25-2006, 08:59 PM
You know, I may have posted the wrong code the second time. Let me do some digging to see if I can't find it. And for the record, the second code did work...:o

Mr Nemo
09-25-2006, 09:10 PM
Ok, got it. Two files, same name, different locations, and I got mixed up.:o
Sorry, about that. This is the working code...

ctpmn
09-27-2006, 01:24 AM
Thats totally perfect OMGSH, Genious!! I didn't even know you could do that thanks soo much! Heres mine if you wanna see it

DrJim
09-27-2006, 08:30 PM
I 'll echo the "I didn't even know you could do that":eek: comment, MrNemo! Did you find it by trial and error or is it documented somewhere and, if so, where? Also, are there similar things for arrays? (I’m getting so many of this type of question I’m thinking of starting a new thread and just adding new questions as they come up - my main question now, other than the above about arrays, is does a “substring” type function exist anywhere?)

Also nice looking program cptmn:D , though I'd still echo my warning about making sure you know which direction is “tall” before putting a new object in.

Mr Nemo
09-27-2006, 08:40 PM
I found the method through trial and error, although I believe it is covered in "Learning to Progam with Alice" which was right next to me on the desk the entire time I was programming it. I kinda kicked myself over that one...

DrJim
09-27-2006, 11:55 PM
Per the title of this post, I just looked for a third time and still can't find anything about the if statement menu for a list - specifically the "list is empty" flag which I'm going to find very useful. Also didn't find it in the Herbert text, even though he did go through different data structures and search algorithms.

Did find mention that you have to move an object out to the "object visualization object" temporarily when you're moving it through an array which explains some problems I was having trying to use an array rather than a list - have to say trying to solve cptmn's problem was a good way to learn the quirks of Alice.

Jim