How do I solve this for each action?

  • Yet another "for each" question, i guess it's pretty simple for a normal person, but i'm somewhat retarded

    I got 10 wolves in the map

    Condition:

    Every choose(5,10,15) seconds

    Wolf stamina > 10

    Action:

    Wolf do this blabla

    My question is this: if i dont use "for each" the game picks the SAME of 5/10/15 seconds from the "every X seconds" for ALL the wolves that respond to the criteria (> 10 stamina), right? But if i put "For each wolf" before it, will it actually pick randomly one of the 3 seconds number for every wolf every time?

  • Every (int(random(0,3))*5) seconds

    wolf stamina >10

    This could work, otherwise you need to do a bunch more code for it, which I can write, but may not be worth the coding for a similar result

  • what's the difference between int and round? and what is supposed to do the line you proposed? give a real random number or else? Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I believe it was fixed awhile ago, so that every X with choose or random will proc again the next time it triggers so it re-picks a new X. It used to be always the same X and it repeats itself as I recall I had a similar issue about 6 months ago.

  • I believe it was fixed awhile ago, so that every X with choose or random will proc again the next time it triggers so it re-picks a new X. It used to be always the same X and it repeats itself as I recall I had a similar issue about 6 months ago.

    Looks like it isn't, i've tested now, and when i use for each before the x seconds, only 1 instance performs the action!

  • Then you need to add a Pick All Instance of Wolf, then narrow it with Wolf Stamina < 10

    ie.

    Every 5,10,15 seconds

    Pick All Wolf

    Wolf Stamina < 10

    DO ZZZZ

    If that don't work (it should), then for sure this will work:

    Every 5,10,15 seconds

    * Pick All Wolf

    * Wolf Stamina < 10

    Do ZZZZ.

    * = sub-event.

  • Managed to solve it by adding an instance variable to the object, so each object has its own internal timer:

    [attachment=0:391w8zf9][/attachment:391w8zf9]

    "wolfTimer" goes from 0 to 10 randomly, and when it reaches 10 is does the action (used opacity just to test) and sets the timer back to 0

    The speed 10*dt, would make it the same as "once every 1 second". Making it random will average to once every 2 seconds

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)