Cassandra Posted June 23, 2012 Posted June 23, 2012 This is the code: local tempDat = { "hasAccount", "loggedIn" } function PlayerSave(player) for k, v in pairs(getAllElementData(player)) do for z, x in pairs(impDat) do if k ~= x then print(tostring(k) .." " .. tostring(v)) dbExec(db, "UPDATE `account` SET `??` = ? WHERE `username` = ?", k, v, getPlayerName(player)) end end end end What I want to do is to ignore the values as keys in tempDat when updating the database. But the problem is that it still includes those values. What should be done in order to fix it? Is there another way to solve the problem?
Anderl Posted June 23, 2012 Posted June 23, 2012 Create loop function to loop from determinated index. Then in your function when it reaches the values in 'tempData' just break the loop and continue the loop in the next index by calling the loop function.
Cassandra Posted June 23, 2012 Author Posted June 23, 2012 Create loop function to loop from determinated index.Then in your function when it reaches the values in 'tempData' just break the loop and continue the loop in the next index by calling the loop function. Nice idea.
Anderl Posted June 23, 2012 Posted June 23, 2012 Here is an example: local tempData = { 'hasAccount', 'loggedIn'; } function PlayerSave( player, k ) for i = k, #getAllElementData( player ) do for z, x in pairs( impData ) do if( i == x ) then PlayerSave( player, i + 1 ); return; end outputChatBox( tostring( i ) .. ' - ' .. tostring( getAllElementData( player )[i] ) ); dbExec( db, 'UPDATE `account` SET `??` = ? WHERE `username` = ?', k, v, getPlayerName( player ) ); end end end Not tested. It should work that way: PlayerSave( myPlayerElem, 1 );
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