Posted 23 July 2012 - 07:11 PM
So I have been trying to make an in game ComputerCraft messenger, I got it working quite easily but somehow, I don't even know what I did it just stopped working. I have now used several hours to try to fix it, considering I really don't have all that much lua experience.
I know what my problem is; Whenever the io.read() is in place the listener wont "listen" for other messages which is really annoying me and since, as I said I don't really have any lua experience then I don't know how to fix this problem. Also if someone ends of helping me, please tell me what you've done so that I can learn :)/>/>
PS: I already have a Login program that connects you to rednet that works just fine :o/>/>
I know what my problem is; Whenever the io.read() is in place the listener wont "listen" for other messages which is really annoying me and since, as I said I don't really have any lua experience then I don't know how to fix this problem. Also if someone ends of helping me, please tell me what you've done so that I can learn :)/>/>
PS: I already have a Login program that connects you to rednet that works just fine :o/>/>
--Strings
displayName = ""
--Commands
cShutdown = "/shutdown"
cReboot = "/reboot"
cRestart = "/restart"
cRelog = "/relog"
--Functions
function listener()
event, id, text = os.pullEvent()
if event == "rednet_message" then
print(text)
end
end
function uMessage()
input = io.read()
rednet.broadcast("" .. displayName .. "> " .. input .. "")
end
function loginMessage()
rednet.broadcast("+ " .. displayName .. ", has logged on!")
end
--"displayName Chooser"
print"Please, choose a displayname."
input = io.read()
displayName = input
loginMessage()
--"Reader"/Commands
while true do
listener()
if input == cReboot then
shell.run("reboot")
elseif input == cShutdown then
shell.run("shutdown")
elseif input == cRestart then
shell.run("clear")
shell.run("cd disk/RedNet")
shell.run("clear")
shell.run("Login")
elseif input == cRelog then
shell.run("clear")
shell.run("cd disk/RedNet")
shell.run("clear")
shell.run("Success")
else
uMessage()
end
end