This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Noodle's profile picture

Backspace

Started by Noodle, 06 August 2012 - 05:14 AM
Noodle #1
Posted 06 August 2012 - 07:14 AM
How would one remove a letter from the string in a table
Example
tHistory = {}
tHistory[1] = ""
h = 1

if key == 14 then tHistory[h] = "" ..tHistory[h].. " " end
ChiknNuggets #2
Posted 06 August 2012 - 07:34 AM
i cant see exactly where in your code you would want this but basically just do
tHistory[h] = string.sub(tHistory[h], 1, -2)
Noodle #3
Posted 06 August 2012 - 07:35 AM
Nvm..
For future solutions: string.sub works
tHistory[h] = string.sub(tHistory[h], 1, string.len(tHistory[h]) - 1 )
Noodle #4
Posted 06 August 2012 - 07:37 AM
i cant see exactly where in your code you would want this but basically just do
tHistory[h] = string.sub(tHistory[h], 1, -2)
Want to see my code?
Spoiler
if key == "q" then tHistory[h] = "" ..tHistory[h].. "q" end
if key == "w" then tHistory[h] = "" ..tHistory[h].. "w" end
if key == "e" then tHistory[h] = "" ..tHistory[h].. "e" end
if key == "r" then tHistory[h] = "" ..tHistory[h].. "r" end
if key == "t" then tHistory[h] = "" ..tHistory[h].. "t" end
if key == "y" then tHistory[h] = "" ..tHistory[h].. "y" end
if key == "u" then tHistory[h] = "" ..tHistory[h].. "u" end
if key == "i" then tHistory[h] = "" ..tHistory[h].. "i" end
if key == "o" then tHistory[h] = "" ..tHistory[h].. "o" end
if key == "p" then tHistory[h] = "" ..tHistory[h].. "p" end
if key == "a" then tHistory[h] = "" ..tHistory[h].. "a" end
if key == "s" then tHistory[h] = "" ..tHistory[h].. "s" end
if key == "d" then tHistory[h] = "" ..tHistory[h].. "d" end
if key == "f" then tHistory[h] = "" ..tHistory[h].. "f" end
if key == "g" then tHistory[h] = "" ..tHistory[h].. "g" end
if key == "h" then tHistory[h] = "" ..tHistory[h].. "h" end
if key == "j" then tHistory[h] = "" ..tHistory[h].. "j" end
if key == "k" then tHistory[h] = "" ..tHistory[h].. "k" end
if key == "l" then tHistory[h] = "" ..tHistory[h].. "l" end
if key == "z" then tHistory[h] = "" ..tHistory[h].. "z" end
if key == "x" then tHistory[h] = "" ..tHistory[h].. "x" end
if key == "c" then tHistory[h] = "" ..tHistory[h].. "c" end
if key == "v" then tHistory[h] = "" ..tHistory[h].. "v" end
if key == "b" then tHistory[h] = "" ..tHistory[h].. "b" end
if key == "n" then tHistory[h] = "" ..tHistory[h].. "n" end
if key == "m" then tHistory[h] = "" ..tHistory[h].. "m" end
if key == "1" then tHistory[h] = "" ..tHistory[h].. "1" end
if key == "2" then tHistory[h] = "" ..tHistory[h].. "2" end
if key == "3" then tHistory[h] = "" ..tHistory[h].. "3" end
if key == "4" then tHistory[h] = "" ..tHistory[h].. "4" end
if key == "5" then tHistory[h] = "" ..tHistory[h].. "5" end
if key == "6" then tHistory[h] = "" ..tHistory[h].. "6" end
if key == "7" then tHistory[h] = "" ..tHistory[h].. "7" end
if key == "8" then tHistory[h] = "" ..tHistory[h].. "8" end
if key == "9" then tHistory[h] = "" ..tHistory[h].. "9" end
if key == "0" then tHistory[h] = "" ..tHistory[h].. "0" end
if key == " " then tHistory[h] = "" ..tHistory[h].. " " end
if key == "backspace" then tHistory[h] = string.sub(tHistory[h], 1, string.len(tHistory[h]) - 1 ) end
if key == "return" then
if tHistory[h] == "exit" or tHistory[h] == "quit" then
quit()
elseif tHistory[h] == "move" then
-- Move code here
print("Move")
tHistory[h] = ""
else
x = x + 1
tLines[x] = "Invalid Command: ".. tHistory[h]
tHistory[h] = ""
end
Its virtual console.
EDIT: Caps and other grammar things not working yet.
ChiknNuggets #5
Posted 06 August 2012 - 08:38 AM
ahh thats incredibly overly needed line wise
KaoS #6
Posted 06 August 2012 - 09:00 AM
why all of the code? you should just pick it up as normal and then say


if key~="backspace" and key~="enter" then -- and keep doing that to leave out irregular keys
tHistory[h]=""..tHistory[h]..key
end

that way it adds caps and lowercase fine and just leaves out the keys that aren't chars
Noodle #7
Posted 06 August 2012 - 09:13 AM
I tried that earlier (above) it works, but this looks so much cooler. Having thousands of lines of if statements.. lmao.
IDK, It'll show my hard work (IN NPP).
EDIT: It's weird, I have to block key lshift and rshift.
EDIT: Caps don't work.
KaoS #8
Posted 06 August 2012 - 02:22 PM
yeah, you have to block any key that cc recognises as an event that does not enter in a character, there is of course a very simple way to do it, just return the length of 'key' and only add it to tHistory if it is 1 character long…
KaoS #9
Posted 06 August 2012 - 02:23 PM
because anything that is not a typable character has a key description and that is always at least 3 chars long
KaoS #10
Posted 06 August 2012 - 02:25 PM
then you add arrow key, enter and backspace/delete functionality and you have a functioning input receiver

the problem is while you have no doubt put a lot of work into writing all of those if statements the PC now has to put that much effort into reading it every time you press a key, this drastically slows things down
Noodle #11
Posted 06 August 2012 - 02:49 PM
Why do you triple post?
KaoS #12
Posted 06 August 2012 - 03:07 PM
sorry about that :P/>/> I'm really busy at the moment so can't concentrate