View Full Version : More on mouse events

09-22-2014, 08:14 AM
Is there a way to store the values of the objects the mouse selects in a variable? I usually have to make an event for when the mouse clicks on each single object, which gets kinda sloppy. If I said when the mouse clicks on anything, and stored what the mouse clicked in a variable, I could use if/else statements to trigger the right method, making it much easier to code when there are a lot of objects I want the user to click.


09-22-2014, 08:49 AM
Add an Object Parameter to the Method you wish to call. Drag the method name into the event, and there will be a dropdown for "what was clicked".

It obviously gets more complicated if you have different types of objects because the parts are name differently.

09-22-2014, 08:59 AM
Great! That'll make things a lot easier (I hope :p) Thanks!


09-22-2014, 09:05 AM
Forgot the Demo

09-22-2014, 10:18 AM
Happens to me all the time in emails! I keep forgetting the attachments! :o

09-23-2014, 04:09 PM
So, I took a look at the demo and found that even if you don't click on the t-rex, the action is still performed (its leg moves anyways). I messed around with the world and fixed the issue. There needs to be a method that checks what object was clicked, but it can't grab the variable that is in the parameter in a different method. So, all you do is link the object within the parameter to a world variable, preferably a string, so that the method that initiates the action upon the object that was clicked knows what action to initiate. You can skim through the coding to see what I did. Let me know if it was helpful. There are two dinos. If you click the trex, then the trex nods, if you click the triceratops, then the triceratops nods it's head, but, if you click on the ground or the sky, or any object that is not the trex or the triceratops, then nothing happens.

09-23-2014, 08:40 PM
A major portion of successful design is to create efficient and creative ways to pass information between modules. Global variables are a good way to make information accessible.
My original demo was just a quickie to show how to pass one of the same type of clicked objects into a method.

This one took a few more minutes, but accomplishes the same using lists of similar objects.

There's always a way, but you have to plan it first ;)

09-25-2014, 07:40 AM
Nicely done! Ha ha, I never thought of using lists. That's probably why I'm having so much trouble with my weapon swapping system.

09-25-2014, 08:43 PM
I saw your comment and I realized that's a smart idea... a weapon system with lists... :)