Zizzo, the code works as intended, and gathers only the second and third return values (or the fourth and the fifth in the case of getTargetLimitedWallStop.)
When you see this, you'll want to kick yourself... or well, you'll want to kick something, at any rate - I certainly felt like it!
Code: Select all
--- Calls :getTarget and :canProject to limit the results and returns the same as getTarget
function _M:getTargetLimited(t)
local x, y = self:getTarget(t)
local _ _, x, y = self:canProject(t, x, y)
local target = game.level.map(x, y, Map.ACTOR)
return x, y, target
end
--- Calls :getTarget and :canProject to limit the results and returns the same as getTarget
function _M:getTargetLimitedWallStop(t)
local x, y = self:getTarget(t)
local _ _, _, _, x, y = self:canProject(t, x, y)
local target = game.level.map(x, y, Map.ACTOR)
return x, y, target
end
For some reason, the first underscore is not followed by a comma - and so while it seems like the first two and the the first four return values are discarded, it is actually one less than that in both cases.
While some complex Lua code can use metatables to overload the underscore with strange new capabilities, in this case there seems to be absolutely no point to the extra underscore.
Why they were written in this confusing way I cannot guess!
DarkGod, is there a stylistic reason for it?
They're nifty functions, either way - whatever the reason for this strange overabundance of underscores
