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,
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
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.
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.
Develop games in your browser. Powerful, performant & highly capable.
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.
Put all plats in a family called platFamily
The do this:
+ Sprite overlaps plat
-> platFamily: Set active to 0
-> plat: Set active to 1
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.
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
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!