• 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!

Lua Tables (where to insert them)

reisbro

Member
Joined
May 15, 2017
Messages
94
Solutions
1
Reaction score
7
I am working on a transformation system and to make my scripts less visually poluted I decided to use tables. However, I don't know where I should create them so that I can access them via any .lua file. Should I create a separate .lua file in the data/libs folder or should I put the new table in the data/libs/012-table.lua file?

EDIT (SOLVED): Just so everyone knows, I am using TFS 0.4 rev 3777 on tibia 8.6
I created a .lua file inside data/libs and there I created a table. I don't think the name of the file matters, because you can insert multiple tables there and access them via tablename.variable or tablename.variable if you are using arrays and etc. It worked perfectly! Hope this helps someone in the future haha
 
Last edited:
So 2 different answers haha, would you guys care to elaborate please? But thank you both anyway! I will try both methods in the meanwhile.

To access those tables I should just use #[line] right?
 
If your server has a global file you can place your tables anywhere in there, if not then take @slawkens's advice, however with his you need to include the file it doesn't automatically load.
dofile loads files into whatever or where ever its called
Lua:
dofile('path to file')
Some people will tell you that you have to put dofile at the top of the page, their wrong you can put that anywhere on the page, but the contents of the file will load where you place the dofile.

On TFS you just start the path at the data directory, example
Lua:
dofile('data/myscript.lua')
 
If your server has a global file you can place your tables anywhere in there, if not then take @slawkens's advice, however with his you need to include the file it doesn't automatically load.
dofile loads files into whatever or where ever its called
Lua:
dofile('path to file')
Some people will tell you that you have to put dofile at the top of the page, their wrong you can put that anywhere on the page, but the contents of the file will load where you place the dofile.

On TFS you just start the path at the data directory, example
Lua:
dofile('data/myscript.lua')


I don't have a global.lua file haha, I am on TFS 0.4

So to sum it up, I am going to create my table in a separate file, put it anywhere I want and use the command dofile('directory/table.lua') on the script of the transformation spell I am creating?
 
I don't have a global.lua file haha, I am on TFS 0.4

So to sum it up, I am going to create my table in a separate file, put it anywhere I want and use the command dofile('directory/table.lua') on the script of the transformation spell I am creating?

You don't need to use dofile, as on TFS 0.4 the files are loaded automatically from data/libs directory.
 
Back
Top