Pick other

For questions about using Classic.

Post » Mon May 23, 2011 1:51 pm

Hello everyone,

I have an object called 'plat' and gave it the private variable 'active'. When 'active' = 1, I can control the object. When it's 0 I can't.

By default 'active' is 0 and I can't control it. When my character is overlapping 'plat', 'active' is set to 1.

The problem is that, when the character overlaps 'plat' and active for the overlapping 'plat' is set to 1, I want to set the 'active' for the other instances of 'plat' to 0. (So that you can only control the 'plat' you overlap / have overlapped for the last time).

Does anyone know how to do this?

Thank you very much,
Maarten
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 23, 2011 2:16 pm

Couldn't you just set "active" to zero before you do your collision check?

This would mean that nothing is picked, so all instances of "active" are set to zero, and then when you've checked collision and have a picked instance, you simply set that one to 1.


-> plat: Set 'active' to 0 (all instances of "active" set to zero)
+ Sprite: Sprite overlaps plat
-> plat: Set 'active' to 1

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Mon May 23, 2011 2:29 pm

Thanks for the quick reply KrushBrother!

No I can't, because I want 'active' to remain at 1 until I overlap another instance of 'plat'. That way I can control the 'plat' object until I overlap a new one.
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 23, 2011 3:01 pm

Ahh, right, I see.

Well, I'm sure there's a better way of doing it, but here's the first thing that springs to mind.

I'd check for collision, and if "active" on the picked instance is 0, set it to 2, then use for-each-object to loop through all the instances, changing every 1 to 0, and every 2 to 1.

By the end of the loop, you'll have all zeros except for one instance with 1, which is the one you collided with.

Sounds like it should work. :)

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Mon May 23, 2011 3:16 pm

Thanks Krush!

Will try it out tonight. If anyone reads this and knows of a better way to do this, I'll probably change it if it's better.
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 23, 2011 3:34 pm

Easy way:
Put all plats in a family called platFamily

The do this:
[code:139j5gvh]
+ Sprite overlaps plat
-> platFamily: Set active to 0
-> plat: Set active to 1
[/code:139j5gvh]

Since the condition only picks plat, and not platFamily, then ALL of platFamily will be set to 0. Then in the next action, the plat that was picked in the condition gets set to 1.

This is a variation of the family trick that you may have seen mentioned before on the forums.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon May 23, 2011 3:54 pm

Another way is to ditch the ('active') private variable in plat, and put it in player instead or make it global, and

Player - on collision with plat
----set global('activeplat') to. Plat.uid

Plat - compare uid == global('activeplat')
----plat control actions here
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon May 23, 2011 10:29 pm

I didn't even think about Families. I've tried it (since it's the easiest solution, and easy is often best) and it works like a charm.

Thanks a lot Deadeye, Krush and Lucid!
B
2
S
2
G
1
Posts: 109
Reputation: 1,068


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests