I am currently working on a project which needs to have multiple files included. But there i have a problem. In my main file i am requiering two files which both include a folder. But it doesnt work. The strange is if i include just one script it works.
Here are the important parts of the scripts:
The main file code for the screen which doesnt work:
function GUI.Load()
printConsole("GUI Lib is loading...")
require("lib/gui/modules/GUILib_Frame.txt")
printConsole("GUI Lib is loading...Frame")
require("lib/gui/modules/GUILib_Buttons.txt")
printConsole("GUI Lib is loading...Buttons")
require("lib/gui/modules/GUILib_Draw.txt")
printConsole("GUI Lib is loading...Draw")
end
timer.create("Load",1,1,GUI.Load)
Are you calling StarOS.Boot() straight away? If so, then that's your problem, as requireAll() will load everything in an undefined order and thus probably loaded the draw file first.
and then get rid of the delay in the GUILib_Main file too.
I would also avoid requireAll() completely for a proper dynamic load system and use the result of getScripts() to load your files from lib/staros/modules in a well defined order (alphabetically for example). Having to set a delay should be sending warning signs in your head saying "this is wrong and should not be this awkward".
28-08-2015, 12:52 PM, (This post was last modified: 28-08-2015, 01:05 PM by SuperPlayer.)
Ok i tried that but it broke Starfall. I got lots of error messages:
First this is what i was using:
function GUI.Load()
local Modules = getScripts("lib/gui/modules")
for k ,v in pairs(Modules) do
print(tostring(k))
require(k)
end
end
GUI.Load()
I also tried :
function GUI.Load()
local Modules = getScripts("lib/gui/modules")
for k ,v in pairs(Modules) do
print(tostring(k))
require(k)
end
end
timer.create("Load",0.1,1,GUI.Load)
cl: stack overflow
stack overflow
stack traceback:
SFtarfall/lib/gui/GUILib_Main.txt:21: in function 'func'
SFtarfall/lib/gui/GUILib_Main.txt:113: in function 'Load'
SFtarfall/lib/gui/GUILib_Main.txt:116: in function 'func'
SFtarfall/lib/gui/GUILib_Main.txt:113: in function 'Load'
SFtarfall/lib/gui/GUILib_Main.txt:116: in main chunk
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
[AntiCrash] Connection down - did not receive pong
[AntiCrash] Connection lost - sending ping
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
[ERROR] addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372: attempt to index field 'ExpanderButton' (a nil value)
1. unknown - addons/ulx-tscm/lua/vgui/tscm_chat_label.lua:372
Never mind i got it work by adding two if statements. But i would like to know what brought up the errors.
You required files inside each other. The function getScripts doesn't take any arguments, it just returns every included file, so you were loading every file then every file then every file then...
Starfall Docs Wrote:Returns every included script file in a table of filepath -> function pairs.
Call a function to run the file in the same way as dofile().
Returns: Table of filepath -> function pairs.