Jump to content

Question


Wei

Recommended Posts

I have a question

How could I do an restriction if the function I have is in table like this

local table = { 
[1] = getElementData(player, "day7"), 
[2] = getElementData(player, "day6") -- this should return 8 
} 
  
local count = getElementData(player, "count") -- lets say that is 1 or 2 
    if (table[count] ==  s8)  then 
        -- do thing if function from table returns 8 
    end 
     

I hope you understand

Wei

Link to comment

You mean a loop to check every element in the table and do something with those elements who has a special condition?

local theTable = { 
    [1]="value1", 
    [2]="value2", 
    -- ... 
} 
  
for k=1, #theTable do 
    if theTable[k] == "value1" then 
        -- Do something with the first element 
    end 
end 

Link to comment
local theTable = { 
    [1]=getElementData(player, "Bungee"), 
    [2]=getPlayerMoney(player), 
    [3]=getElementDimension(player), 
    -- ... 
} 
  
for k=1, #theTable do 
    setAccountData(account, "data."..k, theTable[k]) 
end 
  

I wan't to save this as what function returns..

Link to comment
function getTable() 
    local theTable = { 
        [1]=getElementData(player, "Bungee"), 
        [2]=getPlayerMoney(player), 
        [3]=getElementDimension(player), 
        -- ... 
    } 
    return theTable 
end 
  
local gTable = getTable() 
for k=1, #gTable do 
    setAccountData(account, "data."..tostring(k), gTable[k]) 
end 
  
--Or: 
for tableIndex, tableValue in pairs(getTable()) do 
    setAccountData(account, "data."..tostring(tableIndex), tableValue) 
end 

Link to comment

Ah nevermind about this problem. I have another question...

I just want to run function from table... I think I need to use loadstring or _G.. Like

stringFunction = "getPlayerMoney(player)" 
  
  
function run(player) 
    money = -- idk what is here 
end 

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