How do I differentiate between an object and an instance?

Get help using Construct 2

Post » Mon Apr 14, 2014 11:59 am

If i have an object called "A", with an instance boolean variable called "varA", and i copy it many times in the screen. If i write for example a condition: When "A" is touching another object, set "varA" to true. Why when the event occurs with one of the objects, the var is altered in all of them?

How can i set the objects to act independently?
Image
B
13
S
1
Posts: 74
Reputation: 886

Post » Mon Apr 14, 2014 1:33 pm

You need to reference the instance in the event condition. In other words, it will only pick a specific instance if you have a condition for that object. For example:
instance differentiation.png

In this example, when an A hits another A it becomes transparent.
You do not have the required permissions to view the files attached to this post.
ImageImage

Take a look at my My Game Art 'Portfolio'
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

Post » Mon Apr 14, 2014 2:52 pm

Ah, so when the green arrow appears means that im defining behaviors for a specific instance, no?
Image
B
13
S
1
Posts: 74
Reputation: 886

Post » Mon Apr 14, 2014 3:18 pm

But.. in your example "A - Is VarA..." (the second one), there is no possibility of making that event work sepparately for every instance? cause as it is, when varA is true, every "A" in the scenario change its opacity to 20.
Image
B
13
S
1
Posts: 74
Reputation: 886

Post » Mon Apr 14, 2014 3:45 pm

No, the green arrow means it is a trigger (either a action called at some point, or an action that is triggered once while true).

In the comparaison done by @Sumyjkl , only instances of A that have varA to true will be concerned (If I am not mistaken)

However I suggest not trying a collision check between two instances of the same object if possible
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Mon Apr 14, 2014 3:53 pm

Basically in each event, only instances which fulfill your conditions are affected by the action.
ImageImage

Take a look at my My Game Art 'Portfolio'
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

Post » Mon Apr 14, 2014 7:36 pm

Ok, understood the green arrow.

This is the thing. I have some cages in the stage. They are opened when the player interacts with them, but while they are not opened i want them to play an animation each n random seconds. Like they are static, but sometimes they play a moving animation (cause the caged character is trying to get out). Cage element has an instance boolean var where i see if its opened or not, so:

· I start a condition. If "Cage opened boolean" is not true --> Wait random (5) -> Play moving animation.
· After that, i set the object to get back to static animation again and the process is restarted.

For some reason, that random value is always the same for all cages, like the behavior is working for every cage in the stage at the same time, not taking each one an individual random value to start in different times.
Image
B
13
S
1
Posts: 74
Reputation: 886

Post » Mon Apr 14, 2014 7:45 pm

The Wait is causing your problem here resulting in all Cages being selected.

I suggest you use something like a Cage var TimeNextPlay and set it as a random delay equal to time + random delay of your choosing on the start of the layout (for loop through the instances, for example). Then when time < Cage.TimeNextPlay run the animation (providing Cage.opened = false) and also set the next random animation run-time (irrespective of whether Cage.opened = true or false). It takes a while to get used to the filtering of the C2 event system, but it's very powerful when you do get the hang of it.
A big fan of JavaScript. Image Image
B
76
S
20
G
81
Posts: 2,347
Reputation: 50,188

Post » Mon Apr 14, 2014 8:42 pm

I've done it in a similar way than the one you explain and it works.

Thank you very much for the support guys.
Image
B
13
S
1
Posts: 74
Reputation: 886


Return to How do I....?

Who is online

Users browsing this forum: dop2000, truefalcon, vankizzle and 11 guests