victorafael
New Member
- Joined
- Jun 5, 2011
- Messages
- 3
- Reaction score
- 0
I'm developing a code and I need to populate a global table wich will be accessed by npcs, talkactions, actions, etc.
so.. i've created a file "table.lua" and placed it on the Data folder.
then in the global.lua i call the table.lua via dofile('.data/table.lua').
so.. my code is not working..
when i try something like this:
(there will be many values on the table.. so i think that i cannot store it on the global storage)
Well... I've placed a debugPrint on the start of table.lua.. and i've noticed that the file is executed many times when the server is loading...
so.. i guess that i'm missing some reference here...
There's any way to execute the file just one time.. (any kind of requireonce() instead of dofile()) ?
if is not.. there's some way to make a really global variable?
thanks for your time..
----
I dont know how that happened but i'm sure that i've started the thread on Resources/Requests (i even dont know if there's the right place anyway)
so.. i've created a file "table.lua" and placed it on the Data folder.
Code:
table = {}
function insertInTable(key, content)
table[key] = table
debugPrint("table size is now: " .. #table) -- will output 'table size is now: 1'
end
function getTableValue(key)
debugPrint("now table size is: " .. #table) -- will output 'table size is now: 0' :(
return table[key] -- a nil value
end
then in the global.lua i call the table.lua via dofile('.data/table.lua').
so.. my code is not working..
when i try something like this:
Code:
-- file 1
local flagType = 1 --item.actionid
local playerName = getCreatureName(cid)
local playerPos = getCreaturePosition(cid)
local eventType = CEVT_FLAGPLACED
local _time = os.clock()
local _team = getPlayerStorageValue(cid, 2200)
local tbl = {name = playerName, pos = playerPos, event = eventType, time = _time, team = _team}
insertInTable(flagType,tbl) -- 'table size is now: 1'
-- file 2
-- checking the table for events...
local check = getTableValue(1) 'table size is now: 0'
-- (check is nil)
(there will be many values on the table.. so i think that i cannot store it on the global storage)
Well... I've placed a debugPrint on the start of table.lua.. and i've noticed that the file is executed many times when the server is loading...
so.. i guess that i'm missing some reference here...
There's any way to execute the file just one time.. (any kind of requireonce() instead of dofile()) ?
if is not.. there's some way to make a really global variable?
thanks for your time..
----
I dont know how that happened but i'm sure that i've started the thread on Resources/Requests (i even dont know if there's the right place anyway)
Last edited: