How do I guarantee that obstacle map has been regenerated?

0 favourites
  • 5 posts
From the Asset Store
Two types of minimap: "full map" and "player is the center" (square map and radial map)
  • I've struggled with this one as path-finding is asynchronous. Due to this construct 2 actually has a way of dealing with the asynchronous nature of path-finding by having an event that will fire when a path is found (because it does not complete at a strict time such as one tic or after 'x' seconds. No problem there.

    Issue comes in when I regenerate obstacle maps. How do I actually know when its completed? There is no event called 'On obstacle map regeneration complete'. I've tried using wait 0 seconds to force the code to run at the end of a tic however this does not work because it can take more than the tic to complete. I've tried using wait 3 seconds and this seemingly works but i'm simply guessing (and gambling) how long it will take to regen obstacle map and if I guess wrong for the 'longest' time it would ever take then the entire thing falls apart.

    Does anyone have a guaranteed way (strict way) to 'know' when the obstacle map has been regenerated so I can then call a new path-find event? Why is there no event called 'on obstacle map regenerated'?

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This should not be a problem because you should not be pathfinding every tick and you should not be regenerating the obstacle map every tick. If it needs to be fast, you can regenerate a region of the map which is faster than the whole map or as the manual suggests you can add a short wait if you are trying to find paths immediately after regenerating the obstacle map.

  • So i'm not doing pathfinding or regen obstacle map every tic (that would be nuts). I'm only doing regen and pathfinding when I deem the obstacle map 'dirty' in other words something changed in the obstacle map because the user added or deleted something.

    Again I need a guaranteed way of knowing when the obstacle map has been regenerated, exactly like the already existing event 'on path found' does.

  • It says in the description "Completes next tick". So "Wait 0" should be enough. Are you sure it takes more than one tick sometimes? In my tests it's always 1 tick.

  • I figured out the cause but I don't really know why it behaves this way. I had 2 path finding behaviors, one on 2 different families. If I remove the 2nd path-finding behavior from other family it all works as expected. I even tried adding a path-finding behavior to the 2nd family named something else, and it still breaks everything. Maybe your only ever supposed to have 1 path-finding behavior per construct 2 game? Even adding the 2nd path-finder behavior to a different family that has a different sprite named something different with no code, still breaks everything.

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