Seems like you are trying to run 2 processes at the same time. Your "FUNKTION" and the user Input. What Lua Liquidator suggests is to use the Parallel API and run 2 functions at the same time.
Lua Liquidator is his
title, his name is
Lyqyd.
OK, but Im a noob, so can you place it in the script?
I merged your key and receive 'functions' and put in the parallel:
Spoiler
local w, h = term.getSize()
local input = ""
local name = ""
local s_rednet = "back" -- Hier Seite vom Router eingeben! "top","bottom","front","back","right","left"
local options={
"Chat beitreten",
"Mail versenden",
"Wer ist online?",
"NickName aendern",
"Einstellungen",
}
function menu(m)
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("--------- ComputerCraft ChatSuite v1.1_a ---------")
print("------------- by iRedCraft @ YouTube -------------")
print("--------------------------------------------------")
term.setCursorPos(1, 12)
print("Zum auswaehlen: Pfeiltaste hoch / runter!")
n=1
while true do
term.setCursorPos(1,6)
for i=1, #m do
term.clearLine()
if i==n then
print(i, " ["..m[i].."] ")
else
print(i, " ", m[i], " ")
end
end
a, b= os.pullEvent()
if a == "key" then
if b==200 then n=n-1 end
if b==208 then n=n+1 end
if b==28 then break end
end
if n < 1 then n = #m
elseif n > #m then n = 1 end
end
term.clear() term.setCursorPos(1,1)
return n
end
local n = menu(options)
if n == 1 then
repeat
term.clear()
term.setCursorPos(1, 1)
write("Server ID: ")
serverID = tonumber(read())
until serverID ~= "" and type(serverID) == "number"
repeat
term.clear()
term.setCursorPos(1, 1)
write("NickName: ")
name = read()
until serverID ~= "" and not string.find(name, " ")
rednet.open( s_rednet )
rednet.send( serverID, "#CONNECT#"..name )
local cInput = ""
local sBars = ""
local tChatHistory = {}
local cBlink = ""
local cBlinkT = 0
for x=1,w - 1 do
sBars = sBars.."-"
end
end
function draw()
cBlinkT = 0
while true do
sleep( 0 )
cBlinkT = cBlinkT + 1
if cBlinkT == 5 then
if cBlink == "" then
cBlink = "_"
else
cBlink = ""
end
cBlinkT = 0
end
term.clear()
term.setCursorPos(1, 1)
local calch = h - 4
for x=table.getn( tChatHistory ) - calch,table.getn( tChatHistory ) do
if tChatHistory[x] ~= nil then
write( tChatHistory[x] )
end
end
term.setCursorPos( 1, h - 1 )
write( "> "..cInput..cBlink )
term.setCursorPos( 1, h - 2 )
write( sBars )
end
end
function key()
while true do
local event, p1 = os.pullEvent()
if event == "key" then
if p1 == 41 then
rednet.send( serverID, "#QUIT___#"..name )
break
elseif p1 == 14 then
cInput = string.sub( cInput, 1, string.len( cInput ) - 1 )
elseif p1 == 28 then
rednet.send( serverID, "ch_"..cInput )
cInput = ""
end
elseif event == "char" then
cInput = cInput..p1
elseif event == "terminate" then
rednet.send( serverID, "#QUIT___#"..name )
break
elseif event == "rednet_message" then
if ID == serverID then
tChatHistory[table.getn( tChatHistory ) + 1] = MSG
end
end
end
end
parallel.waitForAny( draw, key )
A lot of errors will pop up because:
[indent=1]You're using 'tChatHistory as a table, you but never define it,[/indent]
[indent=1]cBlinkT is never defined either[/indent]
[indent=1].. There are probably more[/indent]