MrCoala Posted February 10, 2016 Share Posted February 10, 2016 Hi, i am trying to create a mod for don't starve together which is so far a real pain! I already created a few lua plugins for other games before so i have a bit lua experience but i am drowning in lua errors.. modmain.lua"]:2: attempt to call global 'require' (a nil value) modmain.lua"]:11: attempt to index global 'io' (a nil value) to mention two of them. I am trying to create a small plugin to help admins to administrate their server because executing lua code through an input field is not very comfortable. Also, do i really have to reload the whole game everytime i change my lua files? Can't the lua universe reload the specific files itself (as implemented by other games) --require("io") --require "util" Admin = {} -- End of config function Admin:Log(str) file = io.open("adminlog.txt", "a") file.writeLine(str) file.close() end Admin:Log("Test") print("[ADMINCOMMANDS] Loading files...") include('hooks.lua') This is my modmain.lua print("[ADMINCOMMANDS] Loading hooks.lua..") -- function ExecuteConsoleCommand(fnstr, guid, x, z) local OldExecuteConsoleCommand = GLOBAL.ExecuteConsoleCommand local function ExecuteConsoleCommand(fnstr, guid, x, z) return OldExecuteConsoleCommand(fnstr, guid, x, z) end This is my hooks.lua (i am not even sure if dst supports: include() Hopefully someone can help me.. Link to comment Share on other sites More sharing options...
Mobbstar Posted February 10, 2016 Share Posted February 10, 2016 "modmain.lua" and "modworldgenmain.lua" don't have direct access to the global environment. Use GLOBAL.require, etc. Also, you can unload packages like this (loading them again might require more work depending on what script you're reloading): package.loaded["prefabs/evergreen"] = nil --delete the existing package Link to comment Share on other sites More sharing options...
MrCoala Posted February 10, 2016 Author Share Posted February 10, 2016 Thank you for your fast reply the GLOBAL. solution was working to acces io but it wont let me access file Quote :13: variable 'file' is not declared However since there is no way to gain access to the global environment i will abort at this point :/ it just would make things too complicated Link to comment Share on other sites More sharing options...
MrCoala Posted February 10, 2016 Author Share Posted February 10, 2016 I think i found it local env = { TUNING=TUNING, modname = modname, pairs = pairs, ipairs = ipairs, print = print, math = math, table = table, type = type, string = string, tostring = tostring, Class = Class, GLOBAL = _G, MODROOT = MODS_ROOT..modname.."/", } i think these are the only functions / calls accessible within a module.. Link to comment Share on other sites More sharing options...
Mobbstar Posted February 11, 2016 Share Posted February 11, 2016 16 hours ago, MrCoala said: i think these are the only functions / calls accessible within a module.. To clarify: You can access any global variable from the modmain environment using GLOBAL. That's a variable for _G, the global environment. This environment only affects modmain.lua and modworldgenmain.lua (and scripts imported from said files using modimport("filename")). Other modules, such as "prefabricated" entities, components, stategraphs, etc. have full access to the global environment per se. Link to comment Share on other sites More sharing options...
Arkathorn Posted February 12, 2016 Share Posted February 12, 2016 I just want to point out that you are in the wrong forum. DST stuff goes here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.