Weird nil value error I can't explain (SOLVED)

for some reason when I run this code I get a “attempt to index global ‘wisppos’ (a nil value) at line 10” error, this is confusing as to my understanding, this occurs when the variable isn’t defined properly, but everything up to line 10 (start after the y-axis conditional) functions correctly, why?

function update(self, dt)
	local playerpos = go.get_position("/pc/player character")
	self.wisppos = go.get_position(".")
	if playerpos.x > self.wisppos.x then
		go.set_position(vmath.vector3((self.wisppos.x+2),self.wisppos.y,self.wisppos.z))
	elseif playerpos.x < self.wisppos.x then
		go.set_position(vmath.vector3((self.wisppos.x-2),self.wisppos.y,self.wisppos.z))
	end
	if playerpos.y > self.wisppos.y then
		go.set_position(vmath.vector3(self.wisppos.x,self.wisppos.y + 2,wisppos.z))
	elseif playerpos.y < self.wisppos.y then
		go.set_position(vmath.vector3(self.wisppos.x,self.wisppos.y - 2,wisppos.z))
	end
end

You’ve written wisppos.z instead of self.wisppos.z for the y conditional lines.

2 Likes

thank you, I’m burnt-out as hell as you can see

1 Like

You have both self.wisppos and wisppos here. Probably not intentional?