Jump to content




Receiver never start receiving


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

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 31 March 2013 - 08:23 AM

Im making a redstone rednet(yes i know that i can use modems but its funniest!)

im trying to find why the computer that has run the program receiving, never show the message that says that it its receiving

the code:


look down

#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 31 March 2013 - 08:47 AM

The problem lays here:
while true do
  if rs.getOutput(PingReceive) then
   break
  else
   if not received then
	if rs.getOutput(line) then
		 received = "1"
		 term.write("1")
	else
		 received = "0"
		 term.write("0")
	end
   else
	if rs.getOutput(line) then
		 received = received.."1"
		 term.write("1")
	else
		 received = received.."0"
		 term.write("0")
	end
   end
  end
  sleep(0)
end

received is not defined, so its always true. That condition will never hit because of the not, wich makes it false.
I suggest using this:
local received = ""
while true do
	if rs.getOutput(PingReceive) then
		break
	end
	if rs.getOutput(line) then
		received = received .. "1"
		term.write("1")
	elseif not rs.getOutput(line) then
		received = received .. "0"
		term.write("0")
	end
	sleep(0)
end

I think it does what you want. If you have questions about this, ask them! :)

Edited by Engineer, 31 March 2013 - 08:51 AM.


#3 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 31 March 2013 - 08:56 AM

View PostEngineer, on 31 March 2013 - 08:47 AM, said:

The problem lays here:
while true do
  if rs.getOutput(PingReceive) then
   break
  else
   if not received then
	if rs.getOutput(line) then
		 received = "1"
		 term.write("1")
	else
		 received = "0"
		 term.write("0")
	end
   else
	if rs.getOutput(line) then
		 received = received.."1"
		 term.write("1")
	else
		 received = received.."0"
		 term.write("0")
	end
   end
  end
  sleep(0)
end

received is not defined, so its always true. That condition will never hit because of the not, wich makes it false.
I suggest using this:
local received = ""
while true do
	if rs.getOutput(PingReceive) then
		break
	end
	if rs.getOutput(line) then
		received = received .. "1"
		term.write("1")
	elseif not rs.getOutput(line) then
		received = received .. "0"
		term.write("0")
	end
	sleep(0)
end

I think it does what you want. If you have questions about this, ask them! :)
still not working....

Im sure that the problem is in [size=4]
[/size]
while run do
  sleep(0)
  if rs.getOutput(PingReceive) then
   sleep(1)
   run = false
  end
end
cause it dont display the ms that is displayed after that ends...

Im was tryiing to resolve the problem, the new code: [size=4]
[/size]
line = "back"
PingSend = "front"
PingReceive = "front"
local floor,modf, insert = math.floor,math.modf, table.insert
local char,format,rep = string.char,string.format,string.rep
local function basen(n,B)/>
if n < 0 then
  n = -n
end
	   local t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~"
   if n < b then
local ret = ""
ret = ret..string.sub(t, (n%B)/>+1,(n%B)/>+1)
return ret
   else
local tob = tostring(basen(math.floor(n/B)/>, B)/>)
local ret = tob..t:sub((n%B)/>+1,(n%B)/>+1)
return ret
   end
end
function toBase(str, base)  --Encodes @str in @base
if not base then return nil end
str = tostring(str)
local res = ""
for i = 1, str:len() do
  if i == 1 then
   res = basen(str:byte(i), base)
  else
   res = res..":"..basen(str:byte(i), base)
  end
end
return res
end
function fromBase(str, base)  --Decodes @str from @base
if not base then return nil end
str = tostring(str)
local bytes = seperate(str, ":")
local res = ""
for i = 1, #bytes do
  res = res..(string.char(basen(tonumber(bytes[i], base), 10)))
end
return res
end
function toBinary(str)  --Encodes @str in binary
if not str then return nil end
str = tostring(str)
return toBase(str, 2)
end
function fromBinary(str)  --Decodes @str from binary
if not str then return nil end
str = tostring(str)
return fromBase(str, 2)
end
function send(tosend)
rs.setOutput(PingSend, true)
sleep(1)
rs.setOutput(PingSend, false)
print("Sending")
for i = 1, #tosend do
  local c = tosend:sub(i,i)
  sleep(0)
  if c=="1" then
   rs.setOutput(line, true)
  else
   rs.setOutput(line, false)
  end
end
rs.setOutput(PingSend, true)
rs.setOutput(line, false)
sleep(3)
rs.setOutput(PingSend, false)
end
function receive()
run = true
while run do
  sleep(0)
  if rs.getOutput(PingReceive) then run = false end
end
print("Receiving")
sleep(1)
local received = ""
while true do
	    if rs.getOutput(PingReceive) then
		    break
	    end
	    if rs.getOutput(line) then
		    received = received .. "1"
		    term.write("1")
	    elseif not rs.getOutput(line) then
		    received = received .. "0"
		    term.write("0")
	    end
	    sleep(0)
end
term.clear()
return fromBinary(received)
end
args = {...}
if args[1]=="-send" then
file = fs.open(args[2], "r")
a = toBinary(file.readAll())
file.close()
send(a)
elseif args[1]=="-receive" then
a = receive()
term.clear()
term.write("Name: ")
b = read()
file = fs.open(b, "w")
file.write(a)
file.close()
else
print("-receive | -send    filename")
end


#4 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 31 March 2013 - 09:14 AM

bump





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users