N3xT Posted August 3, 2016 Share Posted August 3, 2016 Hello guys, I am trying to do a " dxEdit ", I try that but it doesn't work. local text = {} addEventHandler("onClientCharacter", root, function (c) table.insert(text,c) end ) addEventHandler("onClientRender", root, function () dxDrawText(#text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) when I press anything I got a " numbers " in the dxText, example, when I type hello, I got a number 5. so How to fix it ? Link to comment
فاّرس Posted August 3, 2016 Share Posted August 3, 2016 Because you're trying to get how many values in the table You need to use the loop. Link to comment
Captain Cody Posted August 3, 2016 Share Posted August 3, 2016 local text = "" addEventHandler("onClientCharacter", root, function (c) text = text..c end ) addEventHandler("onClientRender", root, function () dxDrawText(text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) Link to comment
LabiVila Posted August 3, 2016 Share Posted August 3, 2016 or you can use this: addEventHandler ("onClientRender", root, function () dxDrawText(table.maxn (text), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 local text = "" addEventHandler("onClientCharacter", root, function (c) text = text..c end ) addEventHandler("onClientRender", root, function () dxDrawText(text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) It's working, but how I can delete the last value? bindKey("backspace", "down", function () text = "" end) or I just can delete all the values ? Link to comment
Captain Cody Posted August 4, 2016 Share Posted August 4, 2016 local text = {} addEventHandler("onClientCharacter", root, function (c) text[#text+1] = c end ) bindKey("backspace", "down", function () text[#text] = nil end) function getText() local Text = "" for i,v in pairs(text) do local Text = Text..v end return Text end addEventHandler("onClientRender", root, function () dxDrawText(getText(), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 local text = {} addEventHandler("onClientCharacter", root, function (c) text[#text+1] = c end ) bindKey("backspace", "down", function () text[#text] = nil end) function getText() local Text = "" for i,v in pairs(text) do local Text = Text..v end return Text end addEventHandler("onClientRender", root, function () dxDrawText(getText(), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) line 19 : bad argument #1 to'pairs' (table expected got string) Link to comment
Captain Cody Posted August 4, 2016 Share Posted August 4, 2016 Oh sorry try this. local text = {} addEventHandler("onClientCharacter", root, function (c) text[#text+1] = c end ) bindKey("backspace", "down", function () text[#text] = nil end) function getText() local TText = "" for i,v in pairs(text) do local TText = TText..v end return TText end addEventHandler("onClientRender", root, function () dxDrawText(getText(), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 Oh sorry try this. local text = {} addEventHandler("onClientCharacter", root, function (c) text[#text+1] = c end ) bindKey("backspace", "down", function () text[#text] = nil end) function getText() local TText = "" for i,v in pairs(text) do local TText = TText..v end return TText end addEventHandler("onClientRender", root, function () dxDrawText(getText(), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) same error. Link to comment
Bonus Posted August 4, 2016 Share Posted August 4, 2016 CodyL your code will not work pairs? local in this for block? local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) text = text .. key end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, ... ) end ) Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 CodyL your code will not work pairs? local in this for block? local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) text = text .. key end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, ... ) end ) It's only writing, nothing in debug Link to comment
Captain Cody Posted August 4, 2016 Share Posted August 4, 2016 I'm sorry I wasn't thinking about that at the time, try this local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) if not key == "backspace" then text = text .. key end end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) -- Updated version of other guys code. Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 I'm sorry I wasn't thinking about that at the time, try this local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) if not key == "backspace" then text = text .. key end end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) -- Updated version of other guys code. Now I can't write Link to comment
Bonus Posted August 4, 2016 Share Posted August 4, 2016 local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) text = text .. key end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) I expected you to fill the dxDrawText Was on mobile phone Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 local text = "" bindKey ( "backspace", "down", function () if text ~= "" then string.sub ( text, 1, #text - 1 ) end end ) addEventHandler ( "onClientCharacter", root, function ( key ) text = text .. key end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) I expected you to fill the dxDrawText Was on mobile phone Ok, now it's writing but can't delete the text Link to comment
Bonus Posted August 4, 2016 Share Posted August 4, 2016 Hmm ... normally I don't use bindKey there, I use onClientKey. Test this: local text = "" addEventHandler ( "onClientKey", root, function ( button, press ) if press then if button == "tab" then text = text .. "\n" elseif button == "backspace" then if #text > 0 then string.sub ( text, 1, #text - 1 ) end end end end ) addEventHandler ( "onClientCharacter", root, function ( key ) text = text .. key end ) addEventHandler ( "onClientRender", root, function () dxDrawText ( text, 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) end ) Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 same, can't delete anything Link to comment
Bonus Posted August 4, 2016 Share Posted August 4, 2016 Lets try this addEventHandler ( "onClientKey", root, function ( button, press ) if press and button == "backspace" then outputChatBox ( "Test" ) end end ) Put this in and try to delete like you normally do. Do you get an output in the chat? Link to comment
Ab-47 Posted August 4, 2016 Share Posted August 4, 2016 Yes, I got "Test" I've done some research, found out some of you guys's biggest mistake Replace: string.sub ( text, 1, #text - 1 ) with text = string.sub ( text, 1, #text - 1 ) should work perfectly. Link to comment
N3xT Posted August 4, 2016 Author Share Posted August 4, 2016 ^ Thanks, now it's working Link to comment
Bonus Posted August 4, 2016 Share Posted August 4, 2016 Oh god, I'm fucking blind ... Hahaha Link to comment
Ab-47 Posted August 5, 2016 Share Posted August 5, 2016 Haha don't worry, it's the smallest mistakes that you cant see even when they're right infront of your eyes, it's what used to happen to me when I was an amateur in coding Good-luck on your code N3xT, was happy to help. 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