Ulysses

General => Developers Corner => Topic started by: LuaTenshi on October 13, 2015, 08:50:03 PM

Title: Value becomes nil/invalid/not a vector.
Post by: LuaTenshi on October 13, 2015, 08:50:03 PM
Code: [Select]
for _,v in next, ents.FindByClass("prop_*") do
local owner = APA.FindOwner(v);
local box = Vector(0,0,0);

if IsValid(owner) and IsValid(v) and not APA.IsWorld(v) then
box = v:LocalToWorld(v:GetCollisionBounds());
if box and isvector(box) then
for _,x in next, ents.FindInBox(box) do
print(v, owner, x)
if IsValid(x) and isPlayer(x) then
makeSpawnGhost(v,owner)
print(x)
end
end
end
end
end

Getting the following error...

bad argument #2 to 'FindInBox' (Vector exp
ected, got no value)

This is not the full code, but I assure you that all the functions work, but for some reason the box variable gets lost.
Title: Re: Value becomes nil/invalid/not a vector.
Post by: roastchicken on October 14, 2015, 12:10:26 PM
Bad argument #2 to 'FindInBox' (Vector expected, got no value)

ents/FindInBox (http://wiki.garrysmod.com/page/ents/FindInBox) takes two arguments, the box minimum and the box maximum. You're taking the return values of Entity/GetCollisionsBounds (http://wiki.garrysmod.com/page/Entity/GetCollisionBounds) and putting it in one variable, when it returns two values. Use boxMin, boxMax = v:LocalToWorld(v:GetCollisionBounds()) and then pass those arguments to ents/FindInBox.
Title: Re: Value becomes nil/invalid/not a vector.
Post by: LuaTenshi on October 14, 2015, 08:11:34 PM
Ugh, a rookie mistake. Now people are gonna laugh at me. Thanks for the help tho.
Title: Re: Value becomes nil/invalid/not a vector.
Post by: Bytewave on October 14, 2015, 08:56:05 PM
Ugh, a rookie mistake. Now people are gonna laugh at me. Thanks for the help tho.
Even professionals make rookie mistakes. Don't look down on yourself. ;)
Title: Re: Value becomes nil/invalid/not a vector.
Post by: JamminR on October 14, 2015, 08:57:02 PM
Now people are gonna laugh at me.
No worries.
It's not just been 'now'.

/me ducks
Title: Re: Value becomes nil/invalid/not a vector.
Post by: Bytewave on October 14, 2015, 09:00:45 PM
No worries.
It's not just been 'now'.

/me ducks
Wooooow, Jam. Fight fire with water, not tears with a burn. :P