iChris Posted June 6, 2009 Share Posted June 6, 2009 The thing is, that I can't use information from pInfo table out of LoadUser() function, but information from testtable table can be used out of LoadUser() function, here is my function: function LoadUser() mysqlConnect = mysql_connect("localhost", "root", "pass", "mta") result = mysql_query(mysqlConnect, "SELECT id FROM users WHERE Name = 'iChris'") if (result) then while true do local row = mysql_fetch_row(result) if (not row) then break end pInfo = {} for i = 1,2 do pInfo[i] = {} for j = 1,2 do pInfo[i][j] = 0 end end --**********************-- pID = 1 pName = 2 --**********************-- pInfo[pID][source] = row[1] pInfo[pName][source] = row[2] --**********************-- end end testtable = {} testtable[1] = 100 end Link to comment
50p Posted June 6, 2009 Share Posted June 6, 2009 Make sure: - you want to get info from pInfo table after the LoadUser() function is called - row is not nil or false after first mysql_fetch_row call, if the while loop breaks before pInfo is declared then you won't be able to use it... Link to comment
iChris Posted June 7, 2009 Author Share Posted June 7, 2009 It seems, like I can't use only values of pInfo outside that function since I put my testtable table under pInfo and I was able to get testtable values outside the function. E: Something wierd: I gave testtable[1] value pInfo[pID][source] (testtable[1] = pInfo[pID][source]) and I was able to use that outside of LoadPlayer() function. Link to comment
50p Posted June 7, 2009 Share Posted June 7, 2009 Where is the testtable? It's outside the "if not row then" line. pInfo is inside the if statement.. what does that mean? It means that pInfo is not created, what does that mean? It means if statement always fails, what does that mean? mysql_query always fails. You should debug it that way. Put some outputDebugString/outputChatBox/outputConsole inside the if statement, if the message doesn't come up it means the "if" failed, so move the output..... line above the if statement, so you'll see if the "while true do" fails (which can't fail). EDIT: Ok, if you got it fixed than just remember about debugging. Link to comment
iChris Posted June 7, 2009 Author Share Posted June 7, 2009 function LoadUser() mysqlConnect = mysql_connect("localhost", "root", "pass", "mta") result = mysql_query(mysqlConnect, "SELECT id FROM users WHERE Name = 'iChris'") if (result) then local row = mysql_fetch_row(result) pInfo = {} for i = 1,2 do pInfo[i] = {} for j = 1,2 do pInfo[i][j] = 0 end end --**********************-- pID = 1 pName = 2 --**********************-- pInfo[pID][source] = row[1] pInfo[pName][source] = row[2] testtable = {} testtable[1] = 100 testtable1 = {} testtable1[1] = pInfo[pName][source] --**********************-- end end I tried this way, I was able to retrive testtable[1] and testtable1[1] but not pInfo values ot of LoadPlayer() function. Also I debug, just I didn't showed it here. Link to comment
iChris Posted June 9, 2009 Author Share Posted June 9, 2009 Got it working, had a logic mistake. 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