How to - When a number of independent actors (e.g. 5) enter an area it triggers an action

MoogusMoogus 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

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2014

    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.

  • MoogusMoogus Member, PRO Posts: 77

    Thanks @socks will do it!

    So obvious when you explained.

    M

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2014

    Watch my GSlogic series this will help you understand building logic and learn to build code.

  • MoogusMoogus Member, PRO Posts: 77
  • MoogusMoogus Member, PRO Posts: 77
    edited September 2014

    @Socks said:
    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.

    @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.

  • ArmellineArmelline Member, PRO Posts: 5,407
    edited September 2014

    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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    if I read one more person say, "it can't be my code"...slowly I turn!

  • ArmellineArmelline Member, PRO Posts: 5,407

    @The_Gamesalad_Guru said:
    if I read one more person say, "it can't be my code"...slowly I turn!

    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.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @Armelline said:
    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.

    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.

  • MoogusMoogus Member, PRO Posts: 77

    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!

  • MoogusMoogus Member, PRO Posts: 77

    @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 !!

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Yep, I always assume I missed something in my code long before I get to "is this a bug"

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Yes it was your code, it was way off. Look inside each actor I rewrote the code to work.

  • MoogusMoogus Member, PRO Posts: 77

    @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.

  • ArmellineArmelline Member, PRO Posts: 5,407

    Glad you got it fixed @Moogus.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2014

    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.

Sign In or Register to comment.