Jump to content




[FIXED]Doesn't send message


  • You cannot reply to this topic
3 replies to this topic

#1 theeboris

  • Members
  • 59 posts
  • LocationThe Nethelands

Posted 24 March 2013 - 08:42 AM

Hello
I have a problem. If I use this code:
connect = function()
print("Opening rednet...")
for _,s in ipairs(rs.getSides()) do
   if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
	rednet.open(s)
	return true
   end
end
print("No modem found")
print("F7 to reboot")
function rawread()
  while true do
   local sEvent, param = os.pullEvent("key")
   if sEvent == "key" then
	if param == 65 then
	 os.reboot()
	end
   end
  end
end
end
connect()
args = {...}
if #args > 0 and #args < 2 then
rednet.send(tonumber(args[1]), "rechat_server_join")
local serverId, serverMessage, serverDistance = rednet.receive(10)
if serverId == arg1 and serverMessage == rechat_join_okay then
  print("Server online")
  run()
else
  print("No response")
end
else
print("Usage: <serverid>")
end
The computer doen't send a message to args[1].
Thanks
Sorry for bad english

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 24 March 2013 - 08:58 AM

Edit: Just for clarification, is your program outputting "No response from server!"? If so, then my guess is that the problem lies in your server program, not this.

It's possible that it's not finding the modem because you don't force a "rawread" and/or ipairs is not gathering all the sides. Try this, and if it doesn't work then please post your server code as well so I can tell if that's the problem.
connect = function()
print("Opening rednet...")
for _,s in pairs(rs.getSides()) do --I changed ipairs to pairs here because ipairs does not always cycle through the entire table if there are separated values
   if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
	rednet.open(s)
	return true
   end
end
print("No modem found")
print("F7 to reboot")
function rawread()
  while true do
   local sEvent, param = os.pullEvent("key")
   if sEvent == "key" then
	if param == 65 then
		 os.reboot()
	end
   end
  end
end
rawread() --You forgot to call rawread so it never forced you to reboot on not finding a modem
end


connect()


args = {...}
--[[
  I'm just cleaning this up a bit for readability. As far as I could tell your own code would work fine.
']]


if #args ~=1 then
  print("Usage: connect <serverid>")
  return
end

rednet.send(tonumber(args[1]), "rechat_server_join") --This should work fine

local serverID, serverMessage, serverDistance = rednet.receive(10)
if not serverID then
  print("No response from server!")
else
  print("Server online")
  --run() --I commented this out because you don't have a run function and it will cause errors. I'm assuming that you are only copying a portion of your code though
end


#3 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 24 March 2013 - 12:10 PM

if serverId == arg1 and serverMessage == rechat_join_okay then
Here arg1 and rechat_join_okay are both variables, not what you wanted them to be.

#4 theeboris

  • Members
  • 59 posts
  • LocationThe Nethelands

Posted 25 March 2013 - 01:04 AM

I have fixed it. The server modem wasn't open...





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users