Wei Posted August 24, 2014 Share Posted August 24, 2014 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
Mr_Moose Posted August 24, 2014 Share Posted August 24, 2014 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
Wei Posted August 25, 2014 Author Share Posted August 25, 2014 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
Et-win Posted August 25, 2014 Share Posted August 25, 2014 "data."..tostring(k) Atleast this Do you mean, as soon as you are going to save it, it has to re-get the element data and then save it? Link to comment
Wei Posted August 25, 2014 Author Share Posted August 25, 2014 I just wan't to run functions trought table, and what function returns it should save as data.index Link to comment
Et-win Posted August 25, 2014 Share Posted August 25, 2014 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
Wei Posted August 25, 2014 Author Share Posted August 25, 2014 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
DiSaMe Posted August 25, 2014 Share Posted August 25, 2014 table[key] = function(arguments) -- function body end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now