MAARS Posted August 26, 2021 Share Posted August 26, 2021 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 Link to comment Share on other sites More sharing options...
CmP Posted August 26, 2021 Share Posted August 26, 2021 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. Link to comment Share on other sites More sharing options...
MAARS Posted September 3, 2021 Author Share Posted September 3, 2021 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 Link to comment Share on other sites More sharing options...
YeetMeister Posted August 26, 2021 Share Posted August 26, 2021 As the same with gg.getFile() you need to implement the storage directory aswell as the script name, i had a module working before Link to comment Share on other sites More sharing options...
MAARS Posted August 26, 2021 Author Share Posted August 26, 2021 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 Link to comment Share on other sites More sharing options...
YeetMeister Posted August 26, 2021 Share Posted August 26, 2021 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 Link to comment Share on other sites More sharing options...
Question
MAARS
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')
Main Script:
Note: my function are currently doing more complex things i just simplified cause the problem is about finding module file
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.