Trying To Get A Module Working, But Can't(SOLVED)

Hi,

I read this documentation below:

I have the following Module named “FPSandMouseXY.lua” in folder “modules”:

-- Put functions in this file to use them in several other scripts.
-- To get access to the functions, you need to put:
-- require "my_directory.my_file"
-- in any script using the functions.

local M = {}

function M.UpdateFPSandMouseXY()
	FPS_FrameCount = (FPS_FrameCount + 1)
	local currentTime = socket.gettime()
	if ( currentTime > (FPS_LastSecond + 1) ) then
		FPS_TenSeconds[FPS_CurrentSecond] = FPS_FrameCount
		if (FPS_CurrentSecond < 10) then
			FPS_CurrentSecond = (FPS_CurrentSecond + 1)
		else
			FPS_CurrentSecond = 0
		end

		for index = 0, 10 do
			FPS_Average = (FPS_Average + FPS_TenSeconds[index])
		end

		FPS_Average = (FPS_Average / 11)
		FPS_Average = math.floor(FPS_Average)

		FPS_LastSecond = socket.gettime()
		FPS_FrameCount = 0
	end

	label.set_text(   "#MouseXY", "FPS=" .. tostring(FPS_Average) .. " [" .. tostring(  math.floor( mX * (360/WindowWidthTrue) )  ) .. "," .. tostring(  math.floor( mY * (640/WindowHeightTrue) )  ) .. "]"   )	
end

return M

I then have this script code:

function init(self)
	-- Add initialization code here
	-- Remove this function if not needed

	local m = require "modules.FPSandMouseXY"
	
	CurrentScreen = 1
	NextScreen = 2
	
	msg.post(".", "acquire_input_focus")
	
	go.set("#FAS-Statue", "scale.x", 0.65)
	go.set("#FAS-Statue", "scale.y", 0.65)
end

function final(self)
	-- Add finalization code here
	-- Remove this function if not needed

	msg.post(".", "release_input_focus")
end

function update(self, dt)
	-- Add update code here
	-- Remove this function if not needed

	m.UpdateFPSandMouseXY()
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Remove this function if not needed

	if message_id == hash("show_level_select") then
		msg.post("#", "enable")
		self.active = true
	elseif message_id == hash("hide_level_select") then
		msg.post("#", "disable")
		self.active = false
	end
end

function on_input(self, action_id, action)
	-- Add input-handling code here
	-- Remove this function if not needed

	mX = action.screen_x
	mY = action.screen_y	
end

function on_reload(self)
	-- Add reload-handling code here
	-- Remove this function if not needed
end

Above does not compile, get the following error message:

The file ‘/modules/FPSandMouseXY.lua’ could not be found.

Any ideas what I am doing wrong?
(trying to create a module for lines of code that I use in every Collection)

Thanks!

J.

Ok, little unclear in the docs, I thought the module folder was the one in project explorer.
It’s actually where it’s stored in the project’s folder.
(EDIT: I mean the projects folder on your hard drive)

local m = require "data/modules.FPSandMouseXY"
m.UpdateFPSandMouseXY()

Above works, moving forward

J.

What is unclear in the docs, exactly?

Sorry, very tired and frustrated with this project’s slow pace.
In project explorer, it does show “data” folder, with “modules” sub folder.
Thanks!

J.

I don’t understand. The project folder as shown in the assets browser is a regular folder on your hard drive. Nothing else.

1 Like

You’re probably dead tired of hearing this but you dove into the deep end of the pool without knowing how to swim.

You’re trying to learn one new programming language (Lua) and one new game dev tool aimed at professional game developers (Defold) while at the same time trying to port an existing game. It’s not going to be smooth sailing from day one. You need to learn the basics of Lua to use Defold and you need to learn the core concepts of Defold. Which is at times quite different from other engines (for good reasons).

In my honest opinion you choose the hard way. We’re here to help you, but if you want to do yourself a favor you really should pause your project and do some Defold tutorials.

5 Likes