Delta time access within modules (SOLVED)

Hello, quick question Defolders, can you access dt from within modules? Every time I try to run this code in another script, I get nil. I can manage to run M.hello.

local M = {}

local message = "Hello world!"

function M.hello()
	print(message)
end

function M.scroll()
	local position = go.get_position()
	position.x = position.x - game_speed * dt
	go.set_position(position)
end

return M




You need to pass dt from the script calling the module function, i.e.

function M.scroll(dt)
	local position = go.get_position()
	position.x = position.x - game_speed * dt
	go.set_position(position)
end

Then when calling:

mymodule.scroll(dt)
5 Likes

That worked perfectly. Thank you very much! Now to refactor some code!

1 Like