Here I want to implement a queue in Lua, which can apply to a lot of scripts I will have in the future. And I have already have the codes to define the queue(Actually copied from Lua guide book)
However, for each script, such as script for entity, I have to define the queue respectively. That is, the same definition is copied and pasted each time, which is really a trouble.
Can I make the queue like vgui table, a global one, which is put somewhere and when GMod start, it will run the definition code automatically. By this, I do not have to paste those definition everywhere. Which folder shall I put?
Thank you for answering.
I would put it in lua/includes/util/
[editline]05:21PM[/editline]
Or make it a Lua module and put it in lua/includes/modules/
It's nothing complicated.
[lua]MyQueue = {1,2,3}[/lua]
Since it's not local it can be accessed anywhere from the same lua state. It will be the same everywhere and any change made to it in a script will be reflected in the other scripts, unless they make a local version of the table to work on.
[lua]local localqueue = MyQueue [/lua]
[QUOTE=Crazy Quebec;21329152]It's nothing complicated.
[lua]MyQueue = {1,2,3}[/lua]
Since it's not local it can be accessed anywhere from the same lua state. It will be the same everywhere and any change made to it in a script will be reflected in the other scripts, unless they make a local version of the table to work on.
[lua]local localqueue = MyQueue [/lua][/QUOTE]
So you mean that I just put these codes on any scripts outside any function, in the so-called main chunk?
Actually it would work anywhere, as long as you don't put local in front of it. That's why using local variables all of the time unless you really need a global one is very important.
Sorry, you need to Log In to post a reply to this thread.