opnaiC Posted May 28, 2018 Share Posted May 28, 2018 Hello, I am scripting a new chat and the stuff I scripted is working. But now I have a problem. In my chat I am printing the first 13 messages in dxDraw. But now I want all indexes to +1, so if there come a 14th message it gets visible. local offset = 14 function drawChat() for i, v in ipairs (chatbox) do if (i < offset) then exports.login:dxDrawBorderedText(v, 36, (210 - ((offset-i)*15)), 411, 210, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) elseif (i == 14) then --what to add ? I want all index to +1, so the new message will get the first index end end end addEventHandler ("onClientRender", root, drawChat) Link to comment
Moderators IIYAMA Posted May 29, 2018 Moderators Share Posted May 29, 2018 (edited) chatbox[#chatbox + 1] = newItem #chatbox returns the table lengte. See table.insert for inserting on to the first item. Edited May 29, 2018 by IIYAMA Link to comment
Moderators IIYAMA Posted May 29, 2018 Moderators Share Posted May 29, 2018 table.insert(chatbox, 1, newItem) This is how you can insert items in to the first index and move the rest of the items up. (Couldn't merge anymore with previous post) Link to comment
opnaiC Posted May 29, 2018 Author Share Posted May 29, 2018 5 hours ago, IIYAMA said: table.insert(chatbox, 1, newItem) This is how you can insert items in to the first index and move the rest of the items up. (Couldn't merge anymore with previous post) local offset = 14 function drawChat() for i, v in ipairs (chatbox) do if (i < offset) then exports.login:dxDrawBorderedText(v..", "..i, 36, (210 - ((offset-i)*15)), 411, 210, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) elseif (i > 13) then table.insert(chatbox, 1, chatbox[i]) end end end addEventHandler ("onClientRender", root, drawChat) Tried this but the game starts freezing. ... Maybe because auf the eventHandler.... I can´t find a solution. Link to comment
Moderators IIYAMA Posted May 29, 2018 Moderators Share Posted May 29, 2018 You are filling your table with infinity items. elseif (i > 13) then local value = chatbox[i] -- get the value chatbox[i] = nil -- delete the item table.insert(chatbox, 1, value) -- re-insert end Link to comment
opnaiC Posted May 29, 2018 Author Share Posted May 29, 2018 (edited) 16 minutes ago, IIYAMA said: You are filling your table with infinity items. elseif (i > 13) then local value = chatbox[i] -- get the value chatbox[i] = nil -- delete the item table.insert(chatbox, 1, value) -- re-insert end It is also not working correctly. I show you a picture maybe you can help me. In the output you can see the text and then the index number. So I want the text with the index 1 to disappear (it should be in the table but not visible). Now I want the new message to output where you can see the text with the 13th index number. The other outputs should move up. BUT the old output should save, so I have it easier to do a scroll function later. Edited May 29, 2018 by opnaiC Link to comment
Moderators IIYAMA Posted May 29, 2018 Moderators Share Posted May 29, 2018 elseif (i > 13) then table.remove(chatbox, 1)-- delete the first item, and move all higher items one down. end I thought you wanted to insert items at the beginning. Link to comment
opnaiC Posted May 29, 2018 Author Share Posted May 29, 2018 (edited) 2 minutes ago, IIYAMA said: elseif (i > 13) then table.remove(chatbox, 1)-- delete the first item, and move all higher items one down. end I thought you wanted to insert items at the beginning. I know I did it now, when you posted this message . Thank you. Its working. So, I have to save the message that got deleted in another table if I want to do a scroll function and return them to the table, right ? Like that: elseif (i > 13) then table.insert (chatboxBuffer, v[1]) table.remove (chatbox, 1) end Edited May 29, 2018 by opnaiC Link to comment
Moderators IIYAMA Posted May 29, 2018 Moderators Share Posted May 29, 2018 yea you can do that. Or just using 1 table. And start looping at a different index. for i=math.max(#chatbox - 13, 1), #chatbox do local v = chatbox[i] end (not sure if you have to use: - 12, - 13 or - 14 to accomplish this) 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