Posted 27 August 2014 - 02:25 AM
Okay so I am trying to recreate the read program, adding my own bits and pieces…
The thing I am stuck on is outputting the table as a string without all the syntax… I found a function in Lua called unpack() which does exactly what I want… but it doesn't seem to be working… are there any other ways?
Here is my code anyway:
Forgot to say it doesn't work because when I print the returned variable it only prints the first entry in the table?
The thing I am stuck on is outputting the table as a string without all the syntax… I found a function in Lua called unpack() which does exactly what I want… but it doesn't seem to be working… are there any other ways?
Here is my code anyway:
function read(sAlt, sStart)
local tReadData = {}
local nPos = 0
xPos, yPos = term.getCursorPos()
term.setCursorPos(1, yPos + 1)
while true do
local args = { os.pullEvent() }
if sStart then
nStart = string.len(sStart)
write(sStart)
end
if args[1] == "key" then
if args[2] == 28 then
return unpack(tReadData)
elseif args[2] == 14 then
-- add back key use table.remove()
-- and clear the char space.
end
elseif args[1] == "char" then
table.insert(tReadData, args[2])
nPos = nPos + 1
if sAlt then
write(sAlt)
else
write(args[2])
end
end
end
end
print("-----------------------")
local text = read()
term.setCursorPos(1,10)
print(text)
Forgot to say it doesn't work because when I print the returned variable it only prints the first entry in the table?
Edited on 27 August 2014 - 12:27 AM