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

[fixed] Rednet

Started by iRichard, 15 November 2013 - 09:13 AM
iRichard #1
Posted 15 November 2013 - 10:13 AM
I try to send and receive information to a computer and a server, but it's not quite right. If the computer is trying to send a message he does not well. He's trying to send the following: Tussenwater (Dutch), but the server receives a space.
Computer code:

local serverid = 64
--> local stationid = Tussenwater <--
local stationnaam = "Tussenwater"
--
for _, v in pairs(rs.getSides()) do
if peripheral.getType(v) == "modem" then rednet.open(v) present = true break end
end
term.clear()
term.setCursorPos( 1, 1 )
term.setBackgroundColor(colors.gray)
print("Opstarten										")
term.setBackgroundColor(colors.black)
print("It is not permitted to use the codes without	 ")
print("permissions!									 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
sleep(3)
while true do
term.clear()
term.setCursorPos( 1, 1 )
term.setBackgroundColor(colors.gray)
print("* Start * Herladen - Start					   ")
term.setBackgroundColor(colors.black)
print("Welkom op										")
print("Maak uw keuze:								   ")
print("* Routebeschrijving							  ")
print("* Informatie borden							  ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
print("												 ")
term.setCursorPos( 11, 2 )
print(stationnaam)
local event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y
if XY == "9,1" and button == 1 then
  term.clear()
  term.setCursorPos( 1, 1 )
  term.setBackgroundColor(colors.gray)
  print("Herladen										 ")
  term.setBackgroundColor(colors.black)
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  sleep(0.30)
  os.reboot()
end
if XY == "1,4" and button == 1 then
  term.clear()
  term.setCursorPos( 1, 1 )
  term.setBackgroundColor(colors.gray)
  print("Routebeschrijving								")
  term.setBackgroundColor(colors.black)
  print("Wachten op server								")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
  print("												 ")
--> rednet.send(serverid, stationid) <--
  rednet.receive(5)
  if message == "route" then
   rednet.receive()
   print(message)
   break
  else
   term.clear()
   term.setCursorPos( 1, 1 )
   term.setBackgroundColor(colors.gray)
   print("Routebeschrijving								")
   term.setBackgroundColor(colors.black)
   print("Verbinden mislukt								")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   print("												 ")
   sleep(3)
  end
end
end
Server code:

local idspijk = 16
--
print("[LOG] Opstarten")
for _, v in pairs(rs.getSides()) do
if peripheral.getType(v) == "modem" then rednet.open(v) present = true break end
end
while true do
print("[LOG] Wachten op informatie")
id, message = rednet.receive()
print("[LOG] Informatie ontvangen")
--> if message == "Tussenwater" then <--
  rednet.send(idspijk, "route")
  print("[LOG] Reactie verzonden")
  rednet.send(idspijk, "Test")
  print("[LOG] Informatie verzonden")
else
print("[ERROR] Ongeldig waarden:")
print(message)
end
end
Who can help me?
Edited on 16 November 2013 - 01:47 AM
Lyqyd #2
Posted 15 November 2013 - 02:40 PM
Split into new topic.

Send stationnaam instead of stationid. You set stationid to the value of whatever is in the variable named Tussenwater, which is nil. Why do you have one with quotes and one with no quotes?
Bomb Bloke #3
Posted 15 November 2013 - 03:35 PM
Sorta moving away from the question a bit:

for i=1,16 do  -- Starts a loop that repeats the code within it 16 times, using "i" as a counter variable.
  print( string.rep(" ",95) )  -- Prints a space repeated 95 times.
end

term.setBackgroundColor(colors.gray)  -- Sets the writing background colour to grey.
term.clear()  -- Converts the whole screen to the current background colour, not just to black!
Lyqyd #4
Posted 15 November 2013 - 04:03 PM
His code could actually just remove the blank printed lines entirely, since the screen would look the same if they were removed.
iRichard #5
Posted 16 November 2013 - 02:46 AM
Problem found, a very small mistake. The quotation marks (") were missing.

local serverid = 64
local stationid = -->"Tussenwater"<--
local stationnaam = "Tussenwater"
Oops. :wacko:/>