How to - When a number of independent actors (e.g. 5) enter an area it triggers an action
Moogus
Member, PRO Posts: 77
Hi guys
@The_Gamesalad_Guru How do I do this ?
When a number of independent actors (e.g. 5) enter an area it triggers an action
Thought it would be straight forward, but finding it a little tricky.
Thanks
M
Comments
Assuming a square area, make an actor that covers the area (you can make it invisible if you don't want to see it).
Make a self.attribute (an integer attribute will do here), let's call it 'counter'.
Give all your actors (the ones you want to detect) the same tag, let's use the tag 'OMG!!!'
Ok, now you need a rule that says: when actor collides with actors with the tag OMG!!! . . . . then change 'counter' to 'counter' +1
Then another rule that says when 'counter' = 5 trigger the action.
Thanks @socks will do it!
So obvious when you explained.
M
Watch my GSlogic series this will help you understand building logic and learn to build code.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru on the case
@Socks Is this a bug as I can't believe its my coding...?!??!
-edit: I tried this first off with 1 actor and it works like a charm, but then...
When I try and change the = to another number, say 2... it doesn't work
I'm using latest stable release.
Linked is a project that shows a way of doing this. It asks the fundamental, time-old question:
❝How many penguins have to be in the pool before it becomes mostly pee?❞
The benefit of using this method is you can move actors in and out of the area and have the count stay accurate.
All graphics are taken from the public domain and can be freely used.
Download it here: https://app.box.com/s/4ugip9pzorre3xt4jbif
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
if I read one more person say, "it can't be my code"...slowly I turn!
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
I agree completely. No matter how good you get at GameSalad, it's always safest to assume first that you made a mistake when things don't work.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
I agree. When I have a problem or question (yes, we vets still do) with logic, I always double check and triple check my end. Funny thing is, it's usually a simple mistake somewhere in the logic stack.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Obviously made a mistake, but where?? That is the question! I will keep going till I find it. As @Braydon_SFX says probably a simple mistake in the stack.
Once found will report back.
Thanks for comments guys... i'm still learning!
@The_Gamesalad_Guru @Socks and anyone else !
Here is a link to what I have done, please let me know whats wrong with it as I have no idea.
With one actor colliding no problems, but change = to something else doesn't.
sorry if this is real noob stuff, but we all have been at some point.
https://app.box.com/s/v3aww4bz06xmtb5y76vs
Thanks for your help guys !!
Yep, I always assume I missed something in my code long before I get to "is this a bug"
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Yes it was your code, it was way off. Look inside each actor I rewrote the code to work.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru Thank You !!! Yay! This is what I learned:
The +1 attribute has to be inside the actors and not in the area actor.
The actors have to change the number on the counter by +1 NOT the area counts how many enter.
The area actor has no rules or attributes inside it is only the trigger for the counter when actor with +1 inside collides with it !
Hurray !!
Thank you @The_Gamesalad_Guru I would have never worked it out.
Glad you got it fixed @Moogus.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
You're welcome. Now you can make the code in the move actor however you want. It's all about how rules work not the actors. When you tagged all the actors the same the rule treats them all as one. So once one overlaps with it, it will ignore the others because they have the same tag. You should watch that logic series. It will help you understand how to build logic. To advance in .gs you need to get the basics down solid.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS