How do I get the timer behaviour to work with individual instances?

Not favoritedFavorited Favorited 0 favourites
  • 10 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • I have a family of (boat) sprites using the timer behaviour to control their individual movement. The boats are supposed to independently move on their own timer, stop, cast a fishing line and then resume movement when the line has returned.

    The problem I am experiencing however is that the boats are moving before their line has returned, and the only thing I can think is causing it is that the wrong boat is triggering off another boat's timer instead of each instance being separate. Is that possible? And is it possible to have a family of sprites act independently off their own timers?

  • Yes, "On timer" can trigger for multiple instances, if their timers expire at the same moment. The easiest solution is to add "For each" condition.

  • Yes, "On timer" can trigger for multiple instances, if their timers expire at the same moment. The easiest solution is to add "For each" condition.

    Where do I add the "for each" condition? It doesn't seem to make a difference if I add it to the "On Timer" condition or the event that starts the timer.

  • You can add it to the same event:

    Boat On Timer "arrived"
    For each Boat 
    

    But your issue may be caused by something else. Can you post a screenshot of your code and explain what exactly goes wrong?

  • These boats in the background are supposed to stop moving, drop a line straight down and reel it back in before they move again, however when these timers trigger it randomly makes the wrong ones begin an action meant for a different boat. Thanks for your help so far by the way, I greatly appreciate you're taking the time to have a look at this.

  • Sorry I don't know how to format the code in the post correctly either, my apologies

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's why I asked to post a screenshot of the code :) The forum always makes a mess of it.

  • That's why I asked to post a screenshot of the code :) The forum always makes a mess of it.

    yeah I just reread your post and realised that's what you asked for haha. My bad! I added it to the previous post.

    So there's a few timers there. One to stop a boat going off the edge of screen, one to stop it to begin fishing for the first time, one to begin fishing every time after and a timer to pause the boat for a second after fishing before it starts moving again.

  • when these timers trigger it randomly makes the wrong ones begin an action meant for a different boat.

    What action? Events 20-21 look good to me, you need "For each" there. The hooks should be created and attached to each boat correctly - you can check this in the debugger.

    Perhaps some other events ignore the fishing state?

    Some names on your screenshots are truncated. Is there only one "crew_b..." family?

    Can you share the project file?

  • > when these timers trigger it randomly makes the wrong ones begin an action meant for a different boat.

    What action? Events 20-21 look good to me, you need "For each" there. The hooks should be created and attached to each boat correctly - you can check this in the debugger.

    Perhaps some other events ignore the fishing state?

    Some names on your screenshots are truncated. Is there only one "crew_b..." family?

    Can you share the project file?

    I've figured out the issue! For event 27 I added "For each sprite_crew_hook" and it works correctly now. I guess without that detail it was attributing random hooks and their "crew_boat_vessel_fam" parents.

    Thanks for your help. I would have continued to have issues without the "for each" on the On Timer events that would have prevent me from finding where I was going wrong here. Much appreciated, I hope you have a wonderful day!

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