ForEach command able to pass argument?
Posted: Fri Jun 19, 2015 2:55 pm
I am trying to make a pathfinding which looks for the shortest distance to certain type of place, and it would be easiest to do it this way:
This code is not complete of course, since first of all there needs to be added that it checks if location type is right and if location have already been checked (otherwise it would loop for ever) etc.
But just to give you the idea, that this way it would be easy to know the distance from current place. But is there any way to do this? For to my understanding using foreach command doesnt let you pass any arguments to the function to be executed?
And if not possible, then please add support for userdata or something to foreach commands to be executed functions.
Code: Select all
function findshortestroad(index, value, distance)
distance = distance + 1
foreach(location.neighbors, findshortestroad(distance)
endfunction
distance = 0
foreach(location.neighbors, findshortestroad(distance))But just to give you the idea, that this way it would be easy to know the distance from current place. But is there any way to do this? For to my understanding using foreach command doesnt let you pass any arguments to the function to be executed?
And if not possible, then please add support for userdata or something to foreach commands to be executed functions.