How can I find the undeclared variable in a function?
I receive error in 4.11 not 4.10
ERROR:
14:31:04: ERROR[ServerThread]: Assignment to undeclared global "yaw" inside a function at ...\..\worlds\FIGHTING SURVIVAL\worldmods\badplayer/api.lua:432.
This error comes up a lot with mobs api. I want to fix but don't know where to pinpoint the problem.
See code here: https://github.com/maikerumine/badplayer/blob/master/api.lua#L432
- Code: Select all
if self.state == "stand" then
-- randomly turn
if math.random(1, 4) == 1 then
-- if there is a player nearby look at them
local lp = nil
local s = self.object:getpos()
if self.type == "npc" then
local o = minetest.get_objects_inside_radius(self.object:getpos(), 3)
local yaw = 0
for _,o in ipairs(o) do
if o:is_player() then
lp = o:getpos()
break
end
end
end
if lp ~= nil then
local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z}
yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if lp.x > s.x then
yaw = yaw+math.pi
end
else
yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi)
end
self.object:setyaw(yaw)
end
Any pointers is greatly appreciated.