Vague errors in the script (SOLVED)

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

There is a typo

It should be
factory.create("#rocketfactory")

and

should be
if vmath.length(self.input) > 0 then

2 Likes

Thank you. It was difficult to see a typo because a word was colored blue and I supposed that all is ok. I’m used to Visual Studio, where all typos and mistakes are immediately shown.

You should still get auto-complete in our editor for methods that are part of our API. E.g typing “factory.” should present the methods available in the factory namespace.

1 Like

We could perhaps highlight the errors more clearly also.

1 Like