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

Is it possible to make it shorter?

Started by TheDegree0, 26 August 2012 - 10:14 AM
TheDegree0 #1
Posted 26 August 2012 - 12:14 PM
Hello,
I made an email sistem that uses a server. I made a code for the server but I would like to know if there's any way to make it shorter.

Server Code:

rednet.open("back")
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
serverID = os.computerID()
print "You can't use this computer because its a server!"
print ""
print("Server ID: " ..serverID)
print "-------------"
print "Logs:"
print ""
while true do
from, msg, distance = rednet.receive()
from2, to, distance2 = rednet.receive()
print("Message recived from: " ..from)
print("Sending message to: " ..to)
if (to == "10") then
elseif (to == "9") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "8") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "7") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "6") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "5") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "4") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "3") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "2") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

elseif (to == "1") then
rednet.send(to, msg)
print ""
print "Message Sent"
print "---------------"

-- This part will be changed, now it just says error for testing.
else
print ""
print "Error"
print "---------------"
end
end

Thanks in advance! :D/>/>
TheDegree0 #2
Posted 26 August 2012 - 01:32 PM
I found a way on how to do it but now i'll like to ask another thing.
The server it want to send a message with the ID of who made the message but it says that string was expected. Is there any way to change what's in the variable for example 8 to "8" so its a string?
Kolpa #3
Posted 26 August 2012 - 03:34 PM

tostring(variable)
TheDegree0 #4
Posted 27 August 2012 - 01:18 PM
Thank you! :D/>/>