Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 11 12 13 14 15 … 18 Next »
[Help] Include/Requiring
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pages (2): 1 2 Next »
Threaded Mode
[Help] Include/Requiring
27-08-2015, 03:05 PM,
#1
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
[Help] Include/Requiring
Hello!

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:

--@name StarOS
--@author SuperPlayer
--@require lib/staros/StarOSLib_Main.txt
--@requirecl lib/gui/GUILib_Main.txt
--@updater STEAM_0:0:74694146
--@shared

The main file codes for the screen which does work:

--@name StarOS
--@author SuperPlayer
--@require lib/staros/StarOSLib_Main.txt
--@updater STEAM_0:0:74694146
--@shared

AND

--@name StarOS
--@author SuperPlayer
--@requirecl lib/gui/GUILib_Main.txt
--@updater STEAM_0:0:74694146
--@shared
This is the file GUILib_Main:

--@name GUILib_Main
--@author SuperPlayer
--@updater STEAM_0:0:74694146
--@includedir lib/gui/modules

GUI = { }

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)

This is the file StarOSLib_Main.txt:


--@name StarOSLib_Main
--@author SuperPlayer
--@includedir lib/staros/modules/client
--@includedir lib/staros/modules/server
--@updater STEAM_0:0:74694146

StarOS = { }

function StarOS.Boot()
StarOS.BootStatus = "Initializing..."
requireAll()
StarOS.FilesLoaded = true
end


As i said each of these files alone work but together i get the error:

sv: SF:lib/gui/modules/GUILib_Draw.txt:4: attempt to index global 'GUI' (a nil value)

In the given line is just:
GUI.Buttons = { }

I really hope someone can tell me what i am doing wrong.

SuperPlayer
Find
Reply
27-08-2015, 04:37 PM,
#2
rouing Offline
#RBR15 - Rekt by Rouing 2015
****
Posts: 295
Threads: 27
Joined: Jul 2014
RE: [Help] Include/Requiring
Buttons = { }

What is this love you speak of?
Find
Reply
27-08-2015, 04:51 PM,
#3
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: [Help] Include/Requiring
(27-08-2015, 04:37 PM)rouing Wrote: Buttons = { }

This cant be the solution. I definitly MUST acess GUI in this module. And it works. But not with the other script also included.
Find
Reply
27-08-2015, 05:56 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: [Help] Include/Requiring
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.
Find
Reply
27-08-2015, 05:59 PM,
#5
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: [Help] Include/Requiring
Yes. I am calling it directly. I will test it with a delay when i am on next. Thanks for the advice.
Find
Reply
27-08-2015, 06:09 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: [Help] Include/Requiring
There's no need for a delay. Just place the require statements in the right order, i.e:
--@name StarOS
--@author SuperPlayer
--@requirecl lib/gui/GUILib_Main.txt
--@require lib/staros/StarOSLib_Main.txt
--@updater STEAM_0:0:74694146
--@shared
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". Tongue
Find
Reply
28-08-2015, 12:52 PM, (This post was last modified: 28-08-2015, 01:05 PM by SuperPlayer.)
#7
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: [Help] Include/Requiring
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)

Then i got in my console:


[ERROR] addons/ulx-tscm/lua/tscm/hook.lua:96: stack overflow
1. CallHooks - addons/ulx-tscm/lua/tscm/hook.lua:96
2. unknown - addons/ulx-tscm/lua/tscm/hook.lua:129
3. PrintMessage - [C]:-1
4. print - addons/starfall/lua/starfall/libs_sh/builtins.lua:627
5. Load - SFConfusedtarfall/lib/gui/GUILib_Main.txt:112
6. func - SFConfusedtarfall/lib/gui/GUILib_Main.txt:116
7. require - addons/starfall/lua/starfall/libs_sh/builtins.lua:689
8. Load - SFConfusedtarfall/lib/gui/GUILib_Main.txt:113
9. func - SFConfusedtarfall/lib/gui/GUILib_Main.txt:116
10. require - addons/starfall/lua/starfall/libs_sh/builtins.lua:689
11. Load - SFConfusedtarfall/lib/gui/GUILib_Main.txt:113
12. func - SFConfusedtarfall/lib/gui/GUILib_Main.txt:116
13. require - addons/starfall/lua/starfall/libs_sh/builtins.lua:689
14. Load - SFConfusedtarfall/lib/gui/GUILib_Main.txt:113
15. func - SFConfusedtarfall/lib/gui/GUILib_Main.txt:116
16. require - addons/starfall/lua/starfall/libs_sh/builtins.lua:689

cl: stack overflow
stack overflow
stack traceback:
SFConfusedtarfall/lib/gui/GUILib_Main.txt:21: in function 'func'
SFConfusedtarfall/lib/gui/GUILib_Main.txt:113: in function 'Load'
SFConfusedtarfall/lib/gui/GUILib_Main.txt:116: in function 'func'
SFConfusedtarfall/lib/gui/GUILib_Main.txt:113: in function 'Load'
SFConfusedtarfall/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.
Find
Reply
28-08-2015, 06:32 PM,
#8
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: [Help] Include/Requiring
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...
Find
Reply
28-08-2015, 06:47 PM,
#9
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: [Help] Include/Requiring
Ok thanks for the info. But if i am not mistaken in the SF docs it says you need to put the path into get scripts.
Find
Reply
28-08-2015, 06:52 PM,
#10
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: [Help] Include/Requiring
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.
Nope.
Find
Reply
« Next Oldest | Next Newest »
Pages (2): 1 2 Next »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.