[Solved] How do I pick a specific instance of an object...

  • ... and have another object path find to it?

    i.imgur com/e5KJIr3.png

    This causes all villagers to go to the first town as opposed to the town they should go to.

    I've tried many different ways of picking a specific town but they all to one town only (if I invert the picking condition, the second town) or a random location.

    Thank you for reading.

  • "On Created" is called before the "Create" event returns, so there is no way the gotoUID will have been set, assuming it is set after the create. Just move "Find path" after your create events.

  • Generally speaking, if you want an event to run for each instance of an object instead of one time for all of them, you want to use the system "for each" condition.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "On Created" is called before the "Create" event returns, so there is no way the gotoUID will have been set, assuming it is set after the create. Just move "Find path" after your create events.

    I have done that but all the villagers still go to first town.

    i.imgur.com/wtcXPOe.png

    Here are the relevant events.

    Generally speaking, if you want an event to run for each instance of an object instead of one time for all of them, you want to use the system "for each" condition.

    Thanks for the advice but when the villagers are spawned they are told what to do, so I don't think there is a need for a 'for each'.

    I would use a for each, however, if I wanted to make sure that all the villagers are doing something, but for now, I just want them to go to their respective town when spawned.

    ---

    I know for a fact that when the villagers are spawned their variables are set correctly.

    I feel like there is something REALLY obvious that I am missing...

  • The issue is exactly what blackhornet described so not sure why it was ignored.

  • The issue is exactly what blackhornet described so not sure why it was ignored.

    I've re-arranged the event's multiple times; (pathfound at the bottom, village creates villager mid, on created top), (on created bottom, village creates villager mid, pathfound top), (village spawn villager bottom, pathfound mid, on created top), etc. All go to first town, not their respective town.

    Please help me see what I have missed?

  • When you view the variables they will be correct, but they are not correct in the tick (1/60th of a second) that you look for the path. Your code works like this :

    Spawn villager

    Find path to town.x using default villager.gotoUID (they will all find a path to the same town)

    Change villager.gotoUID after path already found

    It does event 15, then 17/18, then 16.

    You need to wait for a bit to allow all the variables to be set and by that I mean probably 1 second but even a wait of 0.1 secs in the on created event above find path would show it working.

  • Ahh! I thought that Construct 2 would read events going down the line 15,16,17,18 not 15,17/18, then 16.

    I knew it was something obvious lol. Is there a reference that I can refer to about this kind of stuff?

    Thank you for your help plinkie!

    Also thank you blackhornet, oosyrag for your advice!

    ~

    Thinking about it, I guess the 'on Created' is triggered when it is suddenly set to true by something so it pauses any other events that are occurring so it can run. Food for thought.

  • You are right the events will run top to bottom, unless they are a trigger event like on created, see https://www.scirra.com/manual/75/how-events-work

  • Thank you plinkie, for your very fast replies!

    "This indicates the event is triggered. Rather than running once per tick, this event simply runs (or "fires") upon something actually happening. In this case, the event runs when the user hits the Spacebar key on the keyboard. It is never checked any other time. Since triggers run upon an event happening, they aren't checked in top-to-bottom order like other events. This means the ordering of triggers relative to other events is not important (except relative to other triggers of the same type, since triggers still fire top-to-bottom).

    There can only be one trigger in an event, because two triggers cannot fire simultaneously. However, multiple triggers can be placed in 'Or' blocks (see the next section)."

    Useful reference!

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