• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Questions about _G and the Server process

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
How does the server process data, does it reference the _G table if it needs a value or does it use a combination of the script, resource such as an xml and _G table.

I know that certain scripts require the data to be loaded at start-up such as spells, however this doesn't seem to be the case for other things.

I think if we have a better understanding about how the server stores, references & executes data we can write more efficient scripts.

Please share your opinion or theory on this issue.
 
No idea, wish I knew also.

I am self-taught so I actually have almost no idea how things work in the background.
 
I am self-taught so I actually have almost no idea how things work in the background.
kek same thing. Took me 3 months before I understood what people meant about sentence "your variable is wrong"
 
I really don't understand what do you want to know.
If you want to understand how scripts are loaded:
https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp#L336-L363
https://github.com/otland/forgottenserver/blob/master/src/baseevents.cpp#L128-L150

Making it simple: The function from event (ex onUse) is loaded and removed from the global state and its referece is saved with its scriptId (incrementing each event). The scriptId is saved in the event so whenever you want to execute an event it has its reference to execute.

So you can have multiple scripts with function onUse() but they are not going to overwrite each other the function reference is saved when loading and "onUse" reference is erased. So you can't call onUse() in other scripts and don't conflict with them.
 
Instead of looking on _G you should be looking on LUA_REGISTRYINDEX.

I made some simple code using the traverse function that i posted here: https://otland.net/threads/traverse-_g.238205/
With a little modification to show the source of the function instead of the reference and got this:
http://pastebin.com/raw/iM9zeYNt

Without the modification it looks like this:
http://pastebin.com/raw/u7JLDDYs

There you can see every function from every script has its id.
This was not executed in a fresh tfs without any modifcation so you will see some shit that i've added like flylib, ctf and other stuff.
 
Last edited:
Back
Top