• 2d Tables
    1 replies, posted
Now i understand tables are something like arrays but see with an array I can make a 2d array and add data like [CODE]array[0,0] = "player1" array[0,1] = 10.0 array[1,0] = "player2" array[1,1] = 5.0 array[1,0] = "player3" array[1,1] = 7.0 [/CODE]this makes things much easier for swapping around entry's in other languages such as. [CODE]for j:=0 to array.length do for i:=0 to array.length-1 do if (array[i,1] < array[i+1,1])then begin temp = array[i+1] array[i+1] = array[i] array[i] = temp end end end[/CODE]what is the best and easy way to do this for i want to keep 4 or 5 numbers and strings in one table for each person.
[lua]MyTable = {} table.Insert( MyTable, {"player1", 10} ) print(MyTable[1][1], MyTable[1][2]) MyTable[2] = {} MyTable[2][1] = "player2" MyTable[2][2] = 5 print(MyTable[2][1], MyTable[2][2]) [/lua] But it depends what you want to use it for, if it's for keeping data about a player for the while he's on the server then you should just be using the player's table (since in lua everything is a table). So assuming ply is a player you could easilly do ply.MyNumber = 10 or ply.MyTable = {} If this is for keeping data even when the player is offline you should be indexing it by SteamID instead of an arbitrary number.
Sorry, you need to Log In to post a reply to this thread.