Use a for each integer (or real) block, check every array index and compare it to the leading index. In the end you'll end up with the nearest point.
Here's an example of how it could look like:
EventsLocalVariablesPathingCostArray=0<Integer[8]>
Index = 0 <Integer>
NearestIndex = 0 <Integer>
Conditions
Actions
General - For each integer Index from 0 to 7 with increment 1, do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
PathingCostArray[Index]< PathingCostArray[NearestIndex]ThenVariable-SetNearestIndex =IndexElse
It works well except that U moves to all locations but P(0). It chooses the shortest path every time but stops when there is one left (always number 0)
I have just skimmed your trigger, but one thing that is apparent right away is that your array is only 7 long.
try: length = 0 <Integer[8]>
this will let you store values in indexes 0-7.
Also, just use debug messages to pinpoint where things go wrong. It usually becomes apparent very quickly when you get used to debugging. Here are some useful questions that I often use:
How many times does this loop run?
Which indexes are being considered?
Is this if-then-else block ever entered?
I have just skimmed your trigger, but one thing that is apparent right away is that your array is only 7 long.
try: length = 0 <Integer[8]>
this will let you store values in indexes 0-7.
I think this is wrong. As all of my other arrays is built with this system this cannot be it.
But I have maybe found a flaw: when all of the P's are visited and there is only 1 left (number 0) there is nothing to compare with so the trigger thinks that there is no more P's to go to. I don't really know but that it what I see. Though I don't know how to fix this :P
Thanx, I will try to find my problem. I'll edit this if I find it :D
Edit: Lol forgot to edit this. But I found the problem:
My move command was inside of my if-statement. So when I move it outside of it everything worked because then the trigger would find number zero too. Thanks for the help! Much appreciated.
Hello!
I have a unit (lets call it "U"). U will have to go to 1 out of 8 checkpoints (lets call them "P"). But I want U to go to the nearest P.
I thought I would use the "Pathing cost between points" to calculate the length from U to each of the P's. And then maybe store them in an array.
And now for the question: How do I compare multiple integers (or reals) and check which one is the smallest (or largest)?
Happy for answers! :D
Use a for each integer (or real) block, check every array index and compare it to the leading index. In the end you'll end up with the nearest point.
Here's an example of how it could look like:
It works well except that U moves to all locations but P(0). It chooses the shortest path every time but stops when there is one left (always number 0)
Here is the trigger:
Btw, the trigger is fired every time U reaches his destination.
But thanks for this so far. -Ralme
@ralme360: Go
I have just skimmed your trigger, but one thing that is apparent right away is that your array is only 7 long.
try: length = 0 <Integer[8]>
this will let you store values in indexes 0-7.
Also, just use debug messages to pinpoint where things go wrong. It usually becomes apparent very quickly when you get used to debugging. Here are some useful questions that I often use:
How many times does this loop run?
Which indexes are being considered?
Is this if-then-else block ever entered?
I think this is wrong. As all of my other arrays is built with this system this cannot be it.
But I have maybe found a flaw: when all of the P's are visited and there is only 1 left (number 0) there is nothing to compare with so the trigger thinks that there is no more P's to go to. I don't really know but that it what I see. Though I don't know how to fix this :P
@ralme360: Go
Ok, in that case I don't know what might be wrong. Here's a working example in case that can be useful to you.
@Builder_Bob: Go
Thanx, I will try to find my problem. I'll edit this if I find it :D
Edit: Lol forgot to edit this. But I found the problem:
My move command was inside of my if-statement. So when I move it outside of it everything worked because then the trigger would find number zero too. Thanks for the help! Much appreciated.