function init(self)
msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
if action_id == hash("move_left") and action.pressed then
repeat
local pos = go.get_position()
pos.x = pos.x - 10
go.set_position(pos)
local pos = go.get_position()
until cond action.released
end
elseif action_id == hash("move_right") and action.pressed then
local pos = go.get_position()
pos.x = pos.x + 10
go.set_position(pos)
end
end
Don’t you get errors in the console with this? That is the first place you should look when thinks don’t work. 'cond' is not a keyword in Lua, that will cause your build to fail. It also looks like you are making an infinite loop with that repeat...until block, just remove that. action.pressed and action.released will not change within a single input event. Each time on_input is called, it’s a single event, not a continuous thing.
Side note: If you add three backticks ( ` ) before and after you copy your code into your forum post, it will be formatted nicely.
I am guessing you have some background in other coding? Hard to break those habits sometimes.
The LUA can be much simpler. Maybe something like this will work?
function init(self)
msg.post(".", “acquire_input_focus”)
self.pos = go.get_position()
end
function on_input(self, action_id, action)
if action_id == hash(“move_left”) then
self.pos.x = self.pos.x - 10
go.set_position(self.pos)
elseif action_id == hash(“move_right”) then
self.pos.x = self.pos.x + 10
go.set_position(self.pos)
end
end