Questions from Furbuggy
6 posts
• Page 1 of 1
1) Is there anyway to filter an array? I'm really not sure if this is the easiest way of going about it, but so far I have a bunch of locations of ResourceItems placed in an array called "Resources". I want to arrive within 200 units of one ResourceItem and then switch targets to the next closest visible ResourceItem, but not to include the one it is right next to. Any ideas?
BAM! I'm back.
Re: Questions from Furbuggy
Well by the time you travel to within 200 units of anything (assuming your starting position has changed), the distance to everything else will have changed. Unless you want to determine a path from your starting position (which doesn't seem especially logical to me, although I don't know what you're doing), I think it would make sense to pick your destination from the initial array and then generate a new one upon arrival.
However, if you really want to cycle through an array (keeping in mind that I don't actually speak Lua/Python), my instinct would be to use a foreach to cycle through the appropriate key/value pairs.
However, if you really want to cycle through an array (keeping in mind that I don't actually speak Lua/Python), my instinct would be to use a foreach to cycle through the appropriate key/value pairs.
Re: Questions from Furbuggy
You could use a modified version of the closest function; note this is COMPLETELY UNTESTED!
- Code:
function findClosestButNotTooClose(items)
local noCloserThan = 200
local noCloserThanSq = noCloserThan * noCloserThan
local closest = nil
local minDist = 999999999
local loc = bot:getLoc()
for indx, item in ipairs(items) do -- Iterate over list
-- Use distSquared because it is less computationally expensive
-- and works great for comparing distances
local d = loc:distSquared(item:getLoc())
if d < minDist and d > noCloserThanSq then -- Is it the closest yet?
closest = item
minDist = d
end
return closest
end
Re: Questions from Furbuggy
@ K:
yeah, the idea is to have the ship fly to the 2nd closest resource item, that way I can string him along.
@Wat:
Nice, I'll mess around with it and give it a try
yeah, the idea is to have the ship fly to the 2nd closest resource item, that way I can string him along.
@Wat:
Nice, I'll mess around with it and give it a try
BAM! I'm back.
Re: Questions from Furbuggy
You could modify that loop a little to look for the second closest, if that's what you want. As written, it should look for the closest that is more than 200 from your location.
Re: Questions from Furbuggy
oh, well those two things will be the same as long as the closest is less than 200 away- but you're right, actually that would be better, given it does both of my clauses in one action.
BAM! I'm back.
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest