Comparing Multiple Instances of Objects

For questions about using Classic.

Post » Sat Aug 25, 2012 1:39 am

Hey Guys,

I have multiple instances of an enemy and multiple instances of a sprite called Enemybox. Enemy and EnemyBox both have a pv called '#' which i use to set their positions.

+EnemyBox: pick by EnemyBox('#')=Enemy('#')
-EnemyBox: set position to enemy

And then when the player goes into an Enemybox i want the Enemy (with the same '#' as the Enemybox) to set a pv it has called 'target' to 1, so i use

+Enemy: pick by Enemy('#')=EnemyBox('#')
+EnemyBox: overlaps player
-Enemy: set 'target' to 1

But when i do this it makes only 1 random instance of Enemy anywhere on the layout target the player. Can someone please help me?
Thank you.
B
9
S
3
G
1
Posts: 10
Reputation: 710

Post » Sat Aug 25, 2012 9:32 am

Always take care of the order. In your example, no EnemyBox was picked when trying to pick an enemy. So CC looks at the value of the first instance of EnemyBox. Only after that the correct EnemyBox is picked.

Instead of the "pick by" condition, you can use the "compare private variable" condition. It was designed for such a task.

+ EnemyBox: overlaps player
+ Enemy: Value '#' equal to EnemyBox('#')
-> Enemy: Set 'target' to 1

In most cases this should work.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Aug 25, 2012 3:16 pm

Well that worked so thank you :)
B
9
S
3
G
1
Posts: 10
Reputation: 710

Post » Mon Sep 03, 2012 2:10 pm

I'm sorry this is late but your reply didn't solve all of my problems. sometimes when one Enemybox is triggered it will mess up the other Enemyboxes. Here is a cap that that shows what I'm basically trying to do.
CAPMynameisjeff2012-09-03 14:19:00
B
9
S
3
G
1
Posts: 10
Reputation: 710


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests