So, i updated to version 1.10.1
and when controlling the player, Im getting these errors:
As far as I understand, some checks for ‘action’ are needed. But where and what exactly, i cant figure out
So, i updated to version 1.10.1
and when controlling the player, Im getting these errors:
You should probably post the problem code too so we can try and debug it
controller
function on_input(self, action_id, action)
local screen = vmath.vector3(action.x, action.y, 0)
local world = camera.screen_to_world(CAMERA_ID, screen)
action.x = world.x
action.y = world.y
msg.post("#cursor", "input", { action_id = action_id, action = action })
end
function on_message(self, message_id, message, sender)
if message_id == cursor.OVER then
print("Cursor over", message.id, message.group, message.x, message.y)
self.over = message.id
elseif message_id == cursor.OUT then
print("Cursor out", message.id, message.group, message.x, message.y)
self.over = nil
elseif message_id == cursor.PRESSED then
print("Pressed", message.id, message.group, message.x, message.y)
elseif message_id == cursor.RELEASED then
print("Released", message.id, message.group, message.x, message.y)
end
end
player
function on_input(self, action_id, action)
if action_id == CONTROLS.UP then
self.velocity.y = SPEED
elseif action_id == CONTROLS.DOWN then
self.velocity.y = -SPEED
elseif action_id == CONTROLS.LEFT then
self.velocity.x = -SPEED
player_flip(self)
elseif action_id == CONTROLS.RIGHT then
self.velocity.x = SPEED
player_flip(self)
elseif action_id == CONTROLS.INTERACT and action.pressed then
interact(self)
elseif action_id == CONTROLS.SPEED_1 then
msg.post("main:/go#main", "change_speed", { amount = NORMAL_SPEED })
elseif action_id == CONTROLS.SPEED_2 then
msg.post("main:/go#main", "change_speed", { amount = FAST_SPEED })
elseif action_id == CONTROLS.SPEED_3 then
msg.post("main:/go#main", "change_speed", { amount = VERY_FAST_SPEED })
end
end
defold-input cursor.script
local function handle_input(self, action_id, action)
-- ignore accelerometer
if not action_id and action.acc_x then
return
end
action_pos.x = action.x
action_pos.y = action.y
self.action = action
-- mouse movement
if not action_id then
go.set_position(action_pos)
-- click or finger touching screen
elseif action_id == self.action_id then
if action.pressed then
self.touch = true
self.pressed = true
self.skip_frame = true
elseif action.released then
self.touch = false
self.released = true
self.skip_frame = true
end
go.set_position(action_pos)
end
end
function on_input(self, action_id, action)
-- we should only care about calls to on_input if we have specifically acquired input focus
-- if we haven't acquired input focus it is expected that input is sent via on_message from
-- some other script
if self.acquire_input_focus then
handle_input(self, action_id, action)
end
end
error in cursor.script
25 line
action_pos.x = action.x
action_pos.y = action.y
self.action = action
337 line
if self.acquire_input_focus then
handle_input(self, action_id, action)
end
I think the action check here is to see whether action.x
exists for the input. Some actions do not include this variable, so you’re passing a nil variable (the non-existent action.x) to a vector when it wants a number. I recently just had a similar issue.
Thanks for the tip, I was able to fix the error