Jump to content




Rednet Help

computer lua help

5 replies to this topic

#1 joshgreat

  • Members
  • 33 posts

Posted 22 January 2018 - 05:10 PM

Ok basically im trying to make a rednet file server system but when i run the receiver it wont pick up what i send.

Receiver:
os.loadAPI("enc")
function receive()
while true do
term.clear()
rednet.open("top")
term.setCursorPos(1,1)
print("CSOFT DATA SERVER")
local sendid, proto, arg = rednet.receive()
rednet.close("top")
print(sendid, " : ",proto," : ",arg)
if proto == "allocatedisk" then
ad(arg)
else if proto == "deallocatedisk" then
dad(arg)
else if proto == "upload" then
u(arg)
else if proto == "delete" then
d(arg)
else if proto == "download" then
dl(arg)
else if proto == "diskspace" then
ds(arg)
end
end
end
end
end
end
end
end
receive()

Sender:

os.loadAPI("enc")
rednet.open("back")
proto = "csds"
arg = "test2"
print(rednet.isOpen("back"))
rednet.send(2,arg,proto)
rednet.close("back")
print("Sent")
print(proto)
print(arg)

thanks

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 January 2018 - 06:57 PM

Are you certain the receiver's ID is 2?

Also, it seems you have omitted a great deal of code from your receiver code, as you are calling numerous functions which are undefined. I would also recommend using "elseif" instead of nested "if/else" statements. That will dramatically cut down on the number of ends you need. You can avoid calling rednet.close - it's unnecessary. Rednet is not at all like the fs API, thankfully.


#3 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 22 January 2018 - 08:16 PM

Your use of arg and proto are also confusing. You're sending arg first then proto second, but when you receive you assign proto first then arg second (meaning proto will be holding what was sent in arg and arg will be holding what was send in proto).

I would suggest sticking to one or the other convention. Since rednet send uses the second value for protocol and rednet receive uses the third value for protocol, I would recommend using proto strictly for whatever protocol(s) you're using and to change your receive call like so...
local sendid, arg, proto = rednet.receive()

This may necessitate changing some of your other code, but it will make it easier to read and troubleshoot.

Edited by Dog, 22 January 2018 - 08:24 PM.


#4 joshgreat

  • Members
  • 33 posts

Posted 24 January 2018 - 05:16 PM

the program will run but when sending it wont receive it.
the computer id is correct.
i am on my minecraft server if that helps

Edited by joshgreat, 24 January 2018 - 05:16 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 January 2018 - 01:20 AM

Confirm that the systems are in range. Open up the Lua prompt and attempt a transmission from there.

If that works, then I suspect Dog is on the money and your problem relates to the mis-ordering of "arg" and "proto" within the rednet.send() call of the sender script. Your receiver will end up storing the string "test2" in its "proto" variable. Since you don't have any matching condition for that in your list of if/then blocks, your while loop starts the next iteration immediately - clearing the screen so that you don't get time to view the printed message details, and misleading you into thinking nothing was received at all.

Note also that prior to CC1.6, your second variable won't be transmitted at all. You may be better off storing all the values you want to send within a single table, and then transmitting that instead.

#6 joshgreat

  • Members
  • 33 posts

Posted 25 January 2018 - 11:46 AM

Thanks for helping guys i fixed my problem, the term.clear() was in the wrong place so as BB said it cleared the screen before i could see.
code has been fixed.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users