Jump to content

setElementData


Maggi

Recommended Posts

I have question about setElementData function - why I can't save tables in element? It is very useful to allocate some data with player (RGP table of stats) of vehicle (RPG vehicle data: fuel, numberplate, engine number, etc)

so, my code was:

players.lua 
... 
function playerOnJoin () 
     local pdata = {} 
  
     pdata.Money = 1100 
  
     setElementData ( source, "rpgdata", pdata, false ) -- DO NOT SYNC 
      
end 
... 

another module.lua

... 
function someFunction  ( player ) 
   local pdata = getElementData ( player, "rpgdata", false ) 
   pdata.Money = pdata.Money + 1000 -- doesn't work outside this function 
end 
... 

testing pdata == nil -> returns true, why?

Edited by Guest
Link to comment

Syntax

var getElementData ( element theElement, string key [, inherit = true] )

Required Arguments

* theElement: This is the element with data you want to retrieve.

* key: The name of the element data entry you want to retrieve. (Maximum 31 characters.)

Optional Arguments

* inherit: - toggles whether or not the function should go up the hierarchy to find the requested key in case the specified element doesn't have it.

After brainfucking tests I found that I can retrieve tables from elements using getElementData...but, seems to be that this function copies result table instead of returning pointer (handle) to table...so all manipulations with table didn't being saved until I call setElementData... this means that setElementData copies whole table to element data ???

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...