Posted 21 April 2014 - 08:18 PM
What I'm doing is I'm trying to make an on screen keyboard that works through the mouse_click or the monitor_touch events and the way I have it now is each character has it's own variable but I need to combine all the separate strings into a single string t be used in the rest of the script.
The code that handles the keyboard itself is a separate script and I intend to get the input to other scripts through the fs api
The rest of it works fine and if possible I would lie to avoid using tables or for loops like I've seen in other solutions to this issue because I'm still some what new to Lua and don't quit understand how they work yet and I would feel a lot more comfortable not having to deal with stuff I don't understand yet but I don't mind If it's unavoidable.
And also I'm only asking for help on this issue I'm not asking for opinions on how mess this is
But if you do take the time to re do it all in a neater format I wont complain
I suggest running the code yourself to try and get a better understanding on how it works but the goal is to combine the variables:
char1 char2 char3 char4 char5 char6 char7 char8 char9 char10 char11 char12 char13 char14 char15 char16 char17 char18 char19
into 1 single string
Sorry if I was supposed to provide the script in a different way I had a feeling I was doing something wrong when it wouldn't let me paste he whole thing at once and it does have proper indentation in the actual script (figured out how to provide it correctly :)/>)
The code that handles the keyboard itself is a separate script and I intend to get the input to other scripts through the fs api
The rest of it works fine and if possible I would lie to avoid using tables or for loops like I've seen in other solutions to this issue because I'm still some what new to Lua and don't quit understand how they work yet and I would feel a lot more comfortable not having to deal with stuff I don't understand yet but I don't mind If it's unavoidable.
W, H = term.getSize()
WM = W / 2
HM = H / 2
b = paintutils.loadImage('board')
char = " "
char1 = char
char2 = char
char3 = char
char4 = char
char5 = char
char6 = char
char7 = char
char8 = char
char9 = char
char10 = char
char11 = char
char12 = char
char13 = char
char14 = char
char15 = char
char16 = char
char17 = char
char18 = char
char19 = char
char1u = 0
char2u = 0
char3u = 0
char4u = 0
char5u = 0
char6u = 0
char7u = 0
char8u = 0
char9u = 0
char10u = 0
char11u = 0
char12u = 0
char13u = 0
char14u = 0
char15u = 0
char16u = 0
char17u = 0
char18u = 0
char19u = 0
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.setCursorPos(WM - 9,HM - 1)
print("Q W E R T Y U I O P")
term.setCursorPos(WM - 9,HM + 1)
print("A S D F G H J K ENT")
term.setCursorPos(WM - 9,HM + 3)
print("Z X C V B N M L SPA")
paintutils.drawImage(b,WM - 10,HM - 4)
ent = 0
repeat
paintutils.drawLine(WM - 9,HM - 3,WM + 9,HM - 3,colors.white)
term.setCursorPos(WM - 9,HM - 3)
print(char1)
term.setCursorPos(WM - 8,HM - 3)
print(char2)
term.setCursorPos(WM - 7,HM - 3)
print(char3)
term.setCursorPos(WM - 6,HM - 3)
print(char4)
term.setCursorPos(WM - 5,HM - 3)
print(char5)
term.setCursorPos(WM - 4,HM - 3)
print(char6)
term.setCursorPos(WM - 3,HM - 3)
print(char7)
term.setCursorPos(WM - 2,HM - 3)
print(char8)
term.setCursorPos(WM - 1,HM - 3)
print(char9)
term.setCursorPos(WM,HM - 3)
print(char10)
term.setCursorPos(WM + 1,HM - 3)
print(char11)
term.setCursorPos(WM + 2,HM - 3)
print(char12)
term.setCursorPos(WM + 3,HM - 3)
print(char13)
term.setCursorPos(WM + 4,HM - 3)
print(char14)
term.setCursorPos(WM + 5,HM - 3)
print(char15)
term.setCursorPos(WM + 6,HM - 3)
print(char16)
term.setCursorPos(WM + 7,HM - 3)
print(char17)
term.setCursorPos(WM + 8,HM - 3)
print(char18)
term.setCursorPos(WM + 9,HM - 3)
print(char19)
eve, buto, x, y = os.pullEvent()
if eve == "mouse_click" then
if x == 16 and y == 8 then
char = "Q"
elseif x == 18 and y == 8 then
char = "W"
elseif x == 20 and y == 8 then
char = "E"
elseif x == 22 and y == 8 then
char = "R"
elseif x == 24 and y == 8 then
char = "T"
elseif x == 26 and y == 8 then
char = "Y"
elseif x == 28 and y == 8 then
char = "U"
elseif x == 30 and y == 8 then
char = "I"
elseif x == 32 and y == 8 then
char = "O"
elseif x == 34 and y == 8 then
char = "P"
elseif x == 16 and y == 10 then
char = "A"
elseif x == 18 and y == 10 then
char = "S"
elseif x == 20 and y == 10 then
char = "D"
elseif x == 22 and y == 10 then
char = "F"
elseif x == 24 and y == 10 then
char = "G"
elseif x == 26 and y == 10 then
char = "H"
elseif x == 28 and y == 10 then
char = "J"
elseif x == 30 and y == 10 then
char = "K"
elseif x == 16 and y == 12 then
char = "Z"
elseif x == 18 and y == 12 then
char = "X"
elseif x == 20 and y == 12 then
char = "C"
elseif x == 22 and y == 12 then
char = "V"
elseif x == 24 and y == 12 then
char = "B"
elseif x == 26 and y == 12 then
char = "N"
elseif x == 28 and y == 12 then
char = "M"
elseif x == 30 and y == 12 then
char = "L"
elseif x > 31 and x < 35 and y == 10 then
char = "ENT"
elseif x > 31 and x < 35 and y == 12 then
char = " "
end
end
if eve == "mouse_click" then
if char == "ENT" then
ent = 1
elseif char1u == 0 then
char1 = char
char1u = 1
else
if char2u == 0 then
char2 = char
char2u = 1
else
if char3u == 0 then
char3 = char
char3u = 1
else
if char4u == 0 then
char4 = char
char4u = 1
else
if char5u == 0 then
char5 = char
char5u = 1
else
if char6u == 0 then
char6 = char
char6u = 1
else
if char7u == 0 then
char7 = char
char7u = 1
else
if char8u == 0 then
char8 = char
char8u = 1
else
if char9u == 0 then
char9 = char
char9u = 1
else
if char10u == 0 then
char10 = char
char10u = 1
else
if char11u == 0 then
char11 = char
char11u = 1
else
if char12u == 0 then
char12 = char
char12u = 1
else
if char13u == 0 then
char13 = char
char13u = 1
else
if char14u == 0 then
char14 = char
char14u = 1
else
if char15u == 0 then
char15 = char
char15u = 1
else
if char16u == 0 then
char16 = char
char16u = 1
else
if char17u == 0 then
char17 = char
char17u = 1
else
if char18u == 0 then
char18 = char
char18u = 1
else
if char19u == 0 then
char19 = char
char19u = 1
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
until ent == 1
And also I'm only asking for help on this issue I'm not asking for opinions on how mess this is
But if you do take the time to re do it all in a neater format I wont complain
I suggest running the code yourself to try and get a better understanding on how it works but the goal is to combine the variables:
char1 char2 char3 char4 char5 char6 char7 char8 char9 char10 char11 char12 char13 char14 char15 char16 char17 char18 char19
into 1 single string
Edited on 21 April 2014 - 06:41 PM