How do I pick instances one after the other?

0 favourites
  • 11 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I have N (number changes runtime according to spawning/destroy instance) instances of the same sprites in my game and I would like to make them act one after the other and not simultneously.

    What is best ? For each or for 1 to N loop ?

    Is loop the best solution ?

  • You can use a loop with Wait, for example:

    For each Sprite 
    .. Wait 0.2*loopindex
    .. Sprite set invisible
    

    A problem with wait is that once it's running, you can't stop it. So a better solution may be using Timer behavior.

    For each Sprite 
    .. Sprite start timer "make_invisible" for (0.2*loopindex) seconds
    
    Sprite On Timer "make_invisible" 
    .. Sprite set invisible
    
    
  • Thanks dop2000 !

    I was wondering, will this solution based on time and wait will work with Pathfinding that need time to process (calculate path/move along path). Won't it jump to the next instance before Pathfinding processes ?

    My point is to make instances move one after the other so they each calculate their path according to other instances solid location so they don't ovelap.

    I guess what I would need is trigger next instance action (here Pathfinding) once the previous instance finished its move and has sent its new position so that next instance path path could embed the said position to its obstacle map.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I always get For Each wrong when I go with my first thought.

    For Each Sprite , Spite X isActivated , every 0.2 seconds

    TriggerOnce, Pick Nearest (Or any other form that picks1)

    This video will walk you through it:

    youtu.be/QBp9qqq47y4

  • winstreak There are quite a few mistakes in your video.

    Trigger Once condition should never be used with multiple instances. It also makes little sense using it inside loops. And in any case it should come as the last condition in an event.

    Also, For Each loop already picks instances one by one, so picking nearest in a sub-event is unnecessary, it will have no effect.

    Finally, you should put "Every 0.5s" and "Is not activated" condition before "For each", to improve performance and filter the picked scope of instances, before iterating them.

    .

    If you need to pick a random instance, there is a System condition for that.

  • New and Improved

    (Edited video to have new steps removing excess steps and utilizing built in random)

  • Could it be possible to use an iteration ? Not a loop but something like :

    1 - Trigger sprite instances movement routine - instances are solid.

    2 - set X=0

    3 - pick instance X and set other instances to Solid

    4 - regenerate pathfinding obstacle for instance X and find path

    5 - move along path

    6 - on pathfinding arrive set X=X+1, set all instances to Not Solid and go back to 3

    7 - when x=count instance, end routine

  • winstreak It's better to put "Every X seconds" as the first condition for better performance. Also, since you are picking one random instance, you don't need the "for each" loop anymore. So here is the easiest way to do this:

    Every 0.5s
    Sprite Bullet is NOT enabled
    Pick random Sprite
    ....... Sprite set Bullet enabled.
    
  • Laurent So while one instance is moving, all other instances should wait? And only when the first instance reached the target position, then the next instance should begin moving, is this correct?

    Then your plan looks good, although instead of X counter I suggest using an instance variable on the sprite. For example, "isArrived". Pick a random instance with "isArrived=0" (see my previous comment), and when it arrives, change its value to 1.

  • dop2000 That makes sense - So it doesn't attempt every tick - just once every 0.5 seconds

  • dop2000

    That's it ! With a slight detail added :

    "And only when the first instance reached the target position, then the next instance should : "

    - first be able to regenerate its pathfinding obstacle map since all solids instances are now steady

    - start moving along found path,

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