I’m following the tutorial “War battles” and encountered a problem - got errors in the script:
ERROR:SCRIPT: /main/player.script:51: attempt to call field ‘lenght’ (a nil value)
stack traceback:
/main/player.script:51: in function </main/player.script:38>
ERROR:SCRIPT: /main/player.script:22: attempt to index global ‘factoy’ (a nil value)
stack traceback:
/main/player.script:22: in function </main/player.script:14>
The script:
function init(self)
msg.post(".", "acquire_input_focus")
self.moving = false
self.firing = false
self.input = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.speed = 50
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
if self.moving then
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
if self.firing then
factoy.create("#rocketfactory")
end
self.input.x = 0
self.input.y = 0
self.moving = false
self.firing = false
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.input.y = 1
elseif action_id == hash("down") then
self.input.y = -1
elseif action_id == hash("left") then
self.input.x = -1
elseif action_id == hash("right") then
self.input.x = 1
elseif action_id == hash("fire") and action.pressed then
self.firing = true
end
if vmath.lenght(self.input) > 0 then
self.moving = true
self.dir = vmath.normalize(self.input)
end
end
I suppose that a line: “self.input = vmath.vector3()” in the “function init” initializes the vector3() to 0.
This is a screenshot of the main.collection
Thanks in advance