Data Realms Fan Forums
http://45.55.195.193/

Requiring lua files
http://45.55.195.193/viewtopic.php?f=73&t=46232
Page 1 of 1

Author:  Asklar [ Mon Dec 18, 2017 8:44 pm ]
Post subject:  Requiring lua files

So I have this base script that has a couple of functions that multiple other scripts will use, and for the sake of good programming practices I want the other scripts to do a require of that file, however I'm getting errors when I do it.

All the scripts are in Mod.rte/Scripts, but when I try to do require("Mod.rte/Scripts/FileWithFunctions.lua") I get a lengthy "module not found" error with all the places it searched for it, which includes Mod.rte/Scripts/FileWithFunctions.lua.

I also tried with what I found here, but I still can't get it to work.

Any help?

Author:  Bad Boy [ Wed Dec 20, 2017 11:58 am ]
Post subject:  Re: Requiring lua files

You need to use dofile - dofile("Mod.rte/path_to_script"). I think require only accepts things in base or something, so maybe you could do require("../Mod.rte/path_to_script")? I don't quite remember now how it works differently to be honest.

Author:  Asklar [ Wed Dec 20, 2017 8:33 pm ]
Post subject:  Re: Requiring lua files

Using dofile instead of required did it! I've sure learnt a lot of lua now lol, thanks a lot for the help again! :D

Author:  Bad Boy [ Thu Dec 21, 2017 1:46 pm ]
Post subject:  Re: Requiring lua files

Cheers man, keep at it and keep learning!

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/