Using the 'other.variable'

Get help using Construct 2

Post » Tue May 08, 2012 10:47 pm

Hi there,
Fresh out of the package in the Construct community, I have one very basic question:

Here is an example, in a point & clic style game:
I have 2 layouts. When the player clics on a specific object in the first layouts, the second layout is loaded. The second layout's name is store in the clicked object instance variables. This instance variable is called "target".

I'm using an event with the "Mouse" object to detect when the player clic on the specific object "obj_test"

So, in the event sheet, I have a simple condition:
Mouse | On Left button Clicked on obj_test

Then, the action looks like: Go to layout

The problem is... what can I use instead of XXX to call the clicked object?

I need something similar to self.variable but for the other object, the object I'm clicking. In game maker, I'd use other.variable (in a collision test, for example)

Thanks a lot!
Posts: 11
Reputation: 422

Post » Tue May 08, 2012 11:10 pm

Events pick/select instances.

When your mouse - Left button clicked occurs, it selects/pick the clicked instance in the SOL (selected object list).
From there, an action on the object type (in your case obj_test) will have effect only on the picked instances of that object type.
In this case, the single obj_test instance clicked is the one you will use as reference.

So your action go to layout (by name) is

This will automaticly go to the layout which names is stored in the clicked instance of obj_test.

I hope it answers your question.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Posts: 6,932
Reputation: 56,898

Post » Thu May 10, 2012 12:39 pm

Thanks for the link and the answer!

Having a bit of practice on Game maker, the condition/action system is pretty familiar. I have run a test using "" in my expression and it's working fine.

However, what if I want to have the same condition/action for several objects with different names, do I need to change the condition and use each "" or can I use some kind of "" expression, without specifying the button name? That's the kind of stuff I could do with the in game maker.
This way, I could have the same set of condition action for all buttons.

Posts: 11
Reputation: 422

Post » Thu May 10, 2012 4:51 pm

Either use family and a family variable (but you need at least a standard licence I think)
- put all your object in different animation frame of the same object
- set the animation speed to 0
- and change the initial frame (in property panel) for each of your instance in the layout.
That's the technique used before family got implemented... I still use it in some cases though.
Posts: 1,479
Reputation: 16,336

Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], jsutton, LaMachineFactory, makkancs, shadowfan33 and 15 guests