Jump to content
  • 0

Require module


maars

Question

Posted

I am facing problems while requiring module file, both script are in the same directory but the module can not be reached.

Module (file name: 'function.lua')

local func = {}

function func.sayHello()
  gg.alert("Hello World !")
end 

return func

Main Script:

local func = require 'function.lua'
func.sayHello()

 

Note: my function are currently doing more complex things i just simplified cause the problem is about finding module file

5 answers to this question

Recommended Posts

Posted

In your main script try the following code: 

package.path = package.path .. ";" .. gg.getFile():gsub("[^/]+$", "?.lua")
local func = require "function"
func.sayHello()

The first line adds script directory to list of paths in which modules are searched.

Posted
On 8/26/2021 at 5:17 PM, CmP said:

In your main script try the following code: 

package.path = package.path .. ";" .. gg.getFile():gsub("[^/]+$", "?.lua")
local func = require "function"
func.sayHello()

The first line adds script directory to list of paths in which modules are searched.

Working, thanks

Posted
43 minutes ago, YeetMeister said:

As the same with gg.getFile() you need to implement the storage directory aswell as the script name, i had a module working before

Thanks but when i code in lua on my pc, relative path are not needed when requiring module in the same directory.

Edit: still not working even with relative path

Posted
1 hour ago, MAARS said:

Thanks but when i code in lua on my pc, relative path are not needed when requiring module in the same directory.

Edit: still not working even with relative path

Its needed when using GameGuardian. For example you cant load a file with gg.prompt without specifying the path aswell

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.