Jump to content

elementData and {}


iPanda

Recommended Posts

Good day guys. I had a no problem, but rather a question. I've been working with Lua, but with a not yet encountered. Does not work saving a date element if its value is worth in braces "{}"

That's actually made ​​an example for you to understand:

--"elementData" value is {2,0.1,0.3,0.8,0.9} 
-- 
-- 
--EXAMPLE: setElementData(source,"elementData",{2,0.1,0.3,0.8,0.9}) 
  
playerData = {{"elementData"}} 
  
addEventHandler("onPlayerLogin",root,function() 
    account = getPlayerAccount(source) 
    for i,data in ipairs(playerData) do 
        setElementData(source,data[1],getAccountData(account,data[1])) 
    end 
end) 
  
addEventHandler("onPlayerQuit",root,function() 
    local account = getPlayerAccount(source) 
    if account then 
        for i,data in ipairs(playerData) do 
            setAccountData(account,data[1],getElementData(source,data[1])) 
        end 
    end 
end) 

And once again I went to the server, the value of a elementData is not available, it just is not saved. Debug shows that the value of an elementData has not been determined. So it has not been preserved. What to do?

.

Link to comment
Good day guys. I had a no problem, but rather a question. I've been working with Lua, but with a not yet encountered. Does not work saving a date element if its value is worth in braces "{}"

That's actually made ​​an example for you to understand:

--"elementData" value is {2,0.1,0.3,0.8,0.9} 
-- 
-- 
--EXAMPLE: setElementData(source,"elementData",{2,0.1,0.3,0.8,0.9}) 
  
playerData = {{"elementData"}} 
  
addEventHandler("onPlayerLogin",root,function() 
    account = getPlayerAccount(source) 
    for i,data in ipairs(playerData) do 
        setElementData(source,data[1],getAccountData(account,data[1])) 
    end 
end) 
  
addEventHandler("onPlayerQuit",root,function() 
    local account = getPlayerAccount(source) 
    if account then 
        for i,data in ipairs(playerData) do 
            setAccountData(account,data[1],getElementData(source,data[1])) 
        end 
    end 
end) 

And once again I went to the server, the value of a elementData is not available, it just is not saved. Debug shows that the value of an elementData has not been determined. So it has not been preserved. What to do?

.

elementData just a value in table

and u get value ( name ) and set data

i mean like this :

local nData = {  
  { "saveData" } 
} 
  
-- nData [ 1 ] [ 1 ] = "saveData" 
setElementData ( root, nData [ 1 ] [ 1 ], true ) 

just u get name data and u use data with this name

Link to comment

Element data's are stored in tables some thing like this.

  
someData =  {} 
  
setElementData( source, "someTest", "hi") 
-- now it will turn into 
  
someData = { 
       [source's uservalue]={{data="someTest", value="hi"}}, 
} 
-- I am not sure, but I guess they use nested tables, 
  
 

Whenever you quit the user data changes ( i assume that ) and so you can't get it back from the table

I suggest you use tables wherever possible. Do not use setElementData/getElementData until its 100% important because it takes alot of CPU and using it alot can cause lag.

Link to comment

elementData just a value in table

and u get value ( name ) and set data

i mean like this :

local nData = {  
  { "saveData" } 
} 
  
-- nData [ 1 ] [ 1 ] = "saveData" 
setElementData ( root, nData [ 1 ] [ 1 ], true ) 

just u get name data and u use data with this name

You offered me some other option, but with Google translator translation I do not understand. I need my version and how I can save.

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...