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

While Problem

Started by je06, 04 May 2012 - 12:40 AM
je06 #1
Posted 04 May 2012 - 02:40 AM
When i run my program it while not do the while. My Program:
a = 1
write("Port:") – rednet
port = read()
rednet.open(port)
write("Id:") – computer Id
Sip = read()
write("NickName:")
n = read()
while a == 1 do
write("Message:")
m = read()
if m == "exit" then
rednet.send(Sip, n.."Has Exit")
else
rednet.send(Sip, n..":"..m)
end
end

The output is:
Port: – i put j
Id: – i put 22 (I have done a lot of experiments)
NickName: – i put je06

Can any one help?
Luanub #2
Posted 04 May 2012 - 03:36 AM
I don't see anything wrong it should work. I would test it but not to where I can. Only suggestion I can make is since it appears you just want an infinite loop that you can break to do


while true do
code here
end

Then for your exit do something like'

if m == "exit" then
rednet.send(Sip, n.."Has Exit")
break -- to stop the while loop.


Another idea is to combine the two var together before sending the message

msg = (n..":"..m)
rednet.send(Sip, msg )

If none of these work and someone else isn't able to help before I get home, ill try testing it and see what I can come up with.