Syntax Error

I’ve got a script i’m working on for the player, that “should”(if i did it right) spawn and delete a hitbox from the direction the player is facing. But i’m getting a random syntax error on line 30 about my if. I don’t really know why. If anyone thinks they might know why i’m getting this error please let me know what you think. I appreciate any help you guys can give me :slight_smile:

Here’s the script for reference:

function init(self)
	msg.post(".", "acquire_input_focus")
	self.dir = vmath.vector3()
	factory.delete(#Inspectionobject)
end

function final(self)
	-- Add finalization code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
end

function update(self, dt)
	if vmath.length_sqr(self.dir) > 1 then
		self.dir = vmath.normalize(self.dir)
	end
	local p = go.get_position()
	go.set_position(p + self.dir * speed * dt)

	-- Inspection

	local hash("idle")

	if self.dir.x > 0 and -- This one here's 30
	hash("select") factory.create(#Inspectionobject[x.12.5, y.0.5, z.0,]) then
		timer.delay(0.5, factory.delete(#Inspectionobject)
	elseif self.dir.x < 0 and
	hash("select") factory.create(#Inspectionobject[x.-12.5, y.0.5, z.0,]) then
		timer.delay(0.5, factory.delete(#Inspectionobject)
	elseif self.dir.y > 0 and
	hash("select") factory.create(#Inspectionobject[x.0.5, y.12.5, z.0,]) then
		timer.delay(0.5, factory.delete(#Inspectionobject)
	elseif self.dir.y < 0 and
	hash("select") factory.create(#Inspectionobject[x.-0.5, y.12.5, z.0,]) then
		timer.delay(0.5, factory.delete(#Inspectionobject)
	end

function fixed_update(self, dt)
	-- Add update code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Learn more: https://defold.com/manuals/message-passing/
	-- Remove this function if not needed
end

function on_input(self, action_id, action)
	-- Add input-handling code here. The game object this script is attached to
	-- must have acquired input focus:
	--
	--    msg.post(".", "acquire_input_focus")
	--
	-- All mapped input bindings will be received. Mouse and touch input will
	-- be received regardless of where on the screen it happened.
	-- Learn more: https://defold.com/manuals/input/
	-- Remove this function if not needed
end

function on_reload(self)
	-- Add reload-handling code here
	-- Learn more: https://defold.com/manuals/hot-reload/
	-- Remove this function if not needed
end

Did you mean factory.create("#Inspectionobject")? Without the quotes, the # symbol tries to get the length of a table named Inspectionobject, which doesn’t exist.

There’s a lot wrong here, what exactly is this code supposed to do?

2 Likes

if self.dir.x > 0 and – This one here’s 30
hash(“select”) factory.create(#Inspectionobject[x.12.5, y.0.5, z.0,]) then

This is not correct Lua syntax. The first condition, the comparison self.dir.x > 0, is ok, but then what? You have an and which is supposed to be followed by another condition. Instead you have:

hash("select") factory.create(#Inspectionobject[x.12.5, y.0.5, z.0,]) then

This is not a valid comparison or other conditional check. I think you meant something like:

if self.dir.x > 0 and hash("select") then
    factory.create(#Inspectionobject[x.12.5, y.0.5, z.0,])
    timer.delay(0.5, factory.delete(#Inspectionobject)

Some more things to note:

  • This is not valid Lua code: factory.create(#Inspectionobject[x.12.5, y.0.5, z.0,]). Check the documentation for factory.create() to see what it is supposed to look like.
  • This also looks strange: local hash("idle"). It looks like you are missing a variable name, something like this: local foo = hash("idle").
1 Like

Thank you guys!! I know i say this literally every single time, but i’m still learning. So every bit of info helps me allot. I’ve been watching Lua tutorials and reading up on The language and also watching/doing Defold tutorials. But again, still learning, it’s also been hard to find the time recently because i have allot on my plate. So thank you guys for being patient with me.

also to answer your questions:

JustAPotota:

It’s supposed to spawn and then delete a hitbox in the direction the player’s facing so they can inspect things.

And britzl:
That’s for something i haven’t Started on yet. i’m going to make it so that on the initial loading of the game it’ll delete the hitboxes, so you don’t accidentally interact with anything. Because at the moment i have two of them attached to the player for reference.

local hash("idle")

And again. Thank you so much for your time

also thank you again, because stuff like this is great to know:

It looks like you are missing a variable name, something like this:

`local foo = hash("idle")` .

You must pass in a function, not a value to the delay function.
Herte’s the documentation

1 Like