pa3ck Posted November 6, 2013 Share Posted November 6, 2013 I got some problems with tables, I'm not that good at them. Here is my code: addEventHandler('onClientRender', getRootElement(), function() if getKeyState('l') == true then playerC = 0 playerL = 27 columnsP = 28 playersT = {} pt = 0 local swidth, sheight = guiGetScreenSize() local rx, ry = 600, 400 local rectangle = dxDrawRectangle(swidth / 2 - rx / 2, sheight / 2 - ry / 2, rx, ry, tocolor(0, 0, 0,150)) local titleLine = dxDrawLine(swidth / 2 - rx / 2, sheight / 2 - ry / 2 + 28, (swidth / 2) + (rx / 2), sheight / 2 - ry / 2 + 28, tocolor(255, 0, 0, 255)) local columnNameTitle = dxDrawText("Players",swidth / 2 - rx / 2 + 10, sheight / 2 - ry / 2 + 3, swidth, sheight, tocolor(255, 0, 0, 255),1.7) local columnPingTitle = dxDrawText("Ping",swidth / 2 - rx / 2 + 228, sheight / 2 - ry / 2 + 3, swidth, sheight, tocolor(255, 0, 0, 255),1.7) local columnName = dxDrawLine(swidth / 2 - rx / 2 + 220, sheight / 2 - ry / 2, swidth / 2 - rx / 2 + 220, sheight / 2 - ry / 2 + 28, tocolor(255, 0, 0, 255)) local columnPing = dxDrawLine(swidth / 2 - rx / 2 + 274, sheight / 2 - ry / 2, swidth / 2 - rx / 2 + 274, sheight / 2 - ry / 2 + 28, tocolor(255, 0, 0, 255)) for _,name in ipairs(getElementsByType("player")) do pt = pt + 1 playersT[pt] = name outputChatBox(#playersT) playerC = playerC + 28 playerL = playerL + 26 columnsP = columnsP + 26 txt = dxDrawText(getPlayerName(name),swidth / 2 - rx / 2 + 10, sheight / 2 - ry / 2 + playerC, swidth, sheight, tocolor(255, 0, 0, 255), 1.4) line = dxDrawLine(swidth / 2 - rx / 2, sheight / 2 - ry / 2 + playerL, (swidth / 2) + (rx / 2), sheight / 2 - ry / 2 + playerL, tocolor(255, 0, 0, 255)) name = dxDrawLine(swidth / 2 - rx / 2 + 220, sheight / 2 - ry / 2, swidth / 2 - rx / 2 + 220, sheight / 2 - ry / 2 + columnsP, tocolor(255, 0, 0, 255)) ping = dxDrawLine(swidth / 2 - rx / 2 + 274, sheight / 2 - ry / 2, swidth / 2 - rx / 2 + 274, sheight / 2 - ry / 2 + columnsP, tocolor(255, 0, 0, 255)) end end end) My problem is, that the 'outputChatBox(#playersT)' line 19 returns 1 and 2 (there are 2 players). Why is that? Link to comment
Spajk Posted November 6, 2013 Share Posted November 6, 2013 Because of the "for" loop. The first time it goes thru the loop, it adds 1 name to the playerT table and total number of variables in that table is 1. The 2nd time it goes thru the loop it adds one more name to the table and total number of variables in that table is 2. Another thing, dxDrawText and dxDrawLine return true/false, so there's no really a reason to put their returns into globab variables. Link to comment
pa3ck Posted November 6, 2013 Author Share Posted November 6, 2013 Thanks for the reply, but what I ment is that it outputs the #playersT like this: 1 2 1 2 1 2 And it goes on and on. It should output this: 1 2 2 2 Do you get me? Link to comment
Spajk Posted November 6, 2013 Share Posted November 6, 2013 Nope The output for 2 players online should only be: 1 2 Link to comment
xXMADEXx Posted November 6, 2013 Share Posted November 6, 2013 em just a recommendation.. You should make the variables outside the function. Link to comment
pa3ck Posted November 6, 2013 Author Share Posted November 6, 2013 Oh yeah, I got it now! Silly me Thanks! 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