Howto "Find path to" random instance of an object?

Get help using Construct 2

Post » Mon Dec 02, 2013 5:26 pm

Very true :)

Yours is more sophisticated and offers options for manipulation and saving state.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Dec 02, 2013 6:21 pm

[QUOTE=OlivierC] You can store the occupied destinations in a array (by storing the destination instance ID or an actual XY position) then when you want to send an enemy to a destination, you loop through the destination instances and check for each if that destination is already in the array or not. If it is, skip it, else, add it to the array and send the enemy there. This should work until each destination has been assigned an enemy, then it's to you to see what you want to do from here[/QUOTE]

Hi, I have never used arrays. I'am gonna try to understand how to use them following your solution. Thank you
B
5
Posts: 40
Reputation: 307

Post » Wed Dec 04, 2013 11:45 pm

Here's something to try, I haven't tested it though. Unless it is absolutely necessary for you to store the location of every enemy for other reasons, this might be a simpler solution.

Pick a random destination, and use Pick Overlapping Point to check if any enemies are located there. Then do a value comparison: if Enemy.PickedCount is equal to zero. If this is true, then the enemy can travel to the destination.

I would not use this in a while loop. When you are ready for an enemy to travel, you could check a for a free destination once each tick, or even check 3-5 times per tick with a for loop.

I just thought of something, if Pick Overlapping Point does not pick any enemies, I don't know if Enemy.PickedCount will equal zero, since maybe you can't reference Enemy without any actually picked. If my first suggestion doesn't work, try this: do not check if Enemy.PickedCount is equal to zero. Create a local variable, (could be called PickedCount if you want). After using Pick Overlapping Point, use a For Each loop for Enemy. In the action, Add 1 to your local variable PickedCount. In a subevent, do a value comparison: if PickedCount is equal to zero.

I hope this helps!
B
11
S
2
G
1
Posts: 64
Reputation: 1,077

Post » Sun Jan 12, 2014 9:57 pm

Hi, I've been away for a while. Anyway thx for your reply. You guys here are very helpful, I like this community.
B
5
Posts: 40
Reputation: 307

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 33 guests