Function applying only to moving mouse not moving character (SOLVED)


#1

I wanted to have a value continue to increase if the character in the Platformer Tutorial is moving, but this value only increases when the mouse is moving. Below is the code that I used.

function init(self)
	local temperature = 87
	msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
	if action_id == input_left then
		self.moving = true
	elseif action_id == input_right then
		self.moving = true
	elseif action_id == input_jump then
		self.moving = true
	end
end
function update(self,dt)
	if self.moving == true then
		local heat = os.clock()
		temperature = 87 + heat
		local heatnode = gui.get_node("heat")
		gui.set_text(heatnode, "Current Frog Temperature(F): " .. temperature )
		self.moving = false
	end
end

#2

It’s much easier to read if you use the “code fences” option above your messages. Copy the code as it is in your editor and paste between the code fences to display it like this:

function foobar()
     foo = 10
     print(foo)
end

To answer your question:
I believe your problem lies in the fact that the action_ids need to be hashed, unless you already hashed them and are using ‘input_left’ and etc as variables like so:

local input_left = hash("input_left")

Typically it works like this, but if you’re using variables that’s perfectly fine as well:

if action_id == hash("my_input") then
     -- do things...
end

#3

Ok seems to be working now :slight_smile: