Instances and criteria

For questions about using Classic.

Post » Thu Feb 26, 2009 3:46 pm

How do I let an event know which instance to choose, from a sprite object?

Background info:
- 1 sprite object creates every second an instance.
- when an instance collides, it adds 1 to a global variable.
- event created saying: if global variable = 2, start [color=#0000FF:3ibzf3zt]action[/color:3ibzf3zt].

But the [color=#0000FF:3ibzf3zt]action[/color:3ibzf3zt] then takes place involving all instances, even the ones that didn't trigger the event.
An undesirable situation...

Hopefully this description and my wish to select which instance I want to be affected by the [color=#0000FF:3ibzf3zt]action[/color:3ibzf3zt] is clear enough.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Thu Feb 26, 2009 3:54 pm

No, that's not really clear enough. Type your event using pseudocode, or post a screenshot of your event, or better yet upload a .cap.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Feb 26, 2009 4:15 pm

My second attempt to explain it:

B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Thu Feb 26, 2009 4:27 pm

Ah, I see. You have no condition that specifies which yellow block you want to change opacity on in event 18. Defining your condition based solely on a global variable doesn't give you any control over which object is picked.

You'll need some extra conditions in there that specify your yellow block instances:

[code:35tfesr9]
+Is global variable 'Rij1 Counter' equal to 2
+BlockYellow.Y is less than 420
+OR
+BlockYellow is overlapping Block1
+OR
+BlockYellow is overlapping Block2
->BlockYellow: Set opacity to 50
[/code:35tfesr9]

Though honestly I don't understand what you're using the global variable for so I don't know if that's necessary.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Feb 26, 2009 8:27 pm

aha, it worked! Thanks.

Also, I found out that when I entered two conditions (at 18), meant for two different instances (of the same sprite object), it didn't respond to "opacity yellow stone -50%".
I created 18 twice, with 2 conditions within 1 event and it does what I want.


ps: I typed earlier "the criteria is", but I of course I meant "the criteria are".
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Thu Feb 26, 2009 8:31 pm

Use private variables instead of a global variable. There is only one value of a global value. Each instance gets its own unique value with private variables.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Feb 26, 2009 8:43 pm

Ok.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests