To expand on what was already said and answer the original question; you need to pass the mouse coordinates to the update function to have access to it every frame. You can either make it part of the “self” script or a local variable/table to the script, the former probably being the best practice.
example:
function init(self)
self.mouse = nil -- Declare it so you know it is part of the script, It will work without this though
end
function update(self, dt)
if self.mouse then
print("Mouse x position = " .. self.mouse.x)
print("Mouse y position = " .. self.mouse.y)
end
end
function on_input(self, action_id, action)
if not action_id then -- action_id == nil, so this is a mouse movement event
self.mouse = action
end
end