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

Table in Actions not have values

OrochiElf

New Member
Joined
Mar 8, 2013
Messages
21
Reaction score
0
Hello guys, i'm an problem with tables.

This is a code of LIB
Code:
Event_Lightberear = {
   CACHE_GAMEEVENTS = {},
}

local function transformItem(pos, id, newId)
   return doTransformItem(getTileItemById(pos, id).uid, newId)
end

Event_Lightberear.createEvent = function ()
   for _, pos in ipairs(Lightberear_Configurations.Torchs_Positions) do
     local newTorch = doCreateItem(1234, 1, pos)
     doItemSetAttribute(newTorch, "Torch_ID", newTorch)

     local event = addEvent(transformItem, 10, pos, 1234, 4321)
     table.insert(Event_Lightberear.CACHE_GAMEEVENTS, {uid = newTorch, eid = event})
   end
   return true
end

This code make two items in game and add two values in table called (CACHE_GAMEEVENTS), with values (UID and Event ID), but when i call this function in actions, the table return 0 values.

Code:
function onUse(cid, item, frompos, item2, topos)
   print("[Action] Table Value: ".. #Event_Lightberear.CACHE_GAMEEVENTS)
   return true
end

But if i try print the value of table in talkactions, work.

Code:
function onSay(cid, words, param, channel)

   if param == "1" then
     Event_Lightberear.createEvent()
   else
     print("[Talkaction] Table Value: ".. #Event_Lightberear.CACHE_GAMEEVENTS)
   end
   return true
end

lYYLvcG.png


Sorry by the bad english.
 
Last edited:
You cannot do this in TFS 0.4-, lua environment (_G) is not shared between events. However you can use LUA_REGISTRYINDEX that is shared between all lua files.

You can do it like this:

Code:
debug.getregistry().Event_Lightberear = {
    CACHE_GAMEEVENTS = {},
}

And in talkaction/action or any script you're using you do something like:

Code:
local Event_Lightberear = debug.getregistry().Event_Lightberear

function onUse(cid, item, frompos, item2, topos)
   print("[Action] Table Value: ".. #Event_Lightberear.CACHE_GAMEEVENTS)
   return true
end

Forget about it, this is also not shared between files, you can try using globalstorages :\
 
Well, i'm doing tocreate an item and after x time, this item change to other, using addEvent, but if i use an action with this item, i stop this event and start again, what suggest to me?
 
Well, i'm doing tocreate an item and after x time, this item change to other, using addEvent, but if i use an action with this item, i stop this event and start again, what suggest to me?
Store the addEvent id in the item in some attribute and stop the event in the action when the player uses it.
 
Back
Top