Jump to content




Helping with Modem


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

#1 gustavowizard

  • Members
  • 94 posts

Posted 05 June 2014 - 03:24 AM

hello guys!

im trying to set a simple rednet here but im not experienced enought yet, what im trying to set is this:

-A rednet with 1 host computer displaying a monitor text WHEN it gets a message from another computers, using Wireless Modem, so the host would display something like this:

Computer Redstone Signal
1 YES
2 NO
3 YES
4 YES

in this case only computer ID 2 would being receve redstone signal, can anybody help me code this?

i was wandering if i use the rednet.open() command i still need to call the modem on a peripheral and set a channel for it? i cant even begin to work with modens yet :D

#2 Bomb Bloke

    Hobbyist Coder

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

Posted 05 June 2014 - 03:48 AM

When using the rednet API, you do not need to interact with the modem directly (you don't have to wrap it as a peripheral, nor use the modem's API). The rednet API handles all of that for you, making it somewhat easier to get things up and running at the expense of fine control.

What code do you have thus far?

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 June 2014 - 03:49 AM

Firstly this is not what Ask a Pro is for, we do not code things for you, we help people when they have problems with the code they've made, making suggestions for them to try, helping them with problems, or just pointing them in the right direction of the answer.

Now to the question...

No, if you use the Rednet API there is no need to use the Modem API, the Rednet API will open channels for you, it is simply a wrapper for newbies, so use one or the other. Since you're new I suggest using the Rednet API. You'll definitely want to also take a look into the Redstone API so that you can get the status of redstone signals.

EDIT: Ninja'd, nice work Bomb Bloke, didn't even see you come in :P

Edited by theoriginalbit, 05 June 2014 - 03:49 AM.


#4 gustavowizard

  • Members
  • 94 posts

Posted 05 June 2014 - 08:59 PM

This is the code so far, im close to make it works, the problem now is this; when it do not detect redstone on the main room, it does jump to the next check, and check if there is redstone on the next room, however when it does detect the signal on the first room, it do not check for the messages that comes from the second room, i dont have a clue what im doing wrong, i try to use 'while/do' instead of 'if/then' and replace 'else' for other stuff it aint work.

  • term.clear()


  • monitor = peripheral.wrap("top")


  • monitor.setBackgroundColor(colors.black)


  • monitor.clear()


  • monitor.setTextColor(colors.lightBlue)


  • monitor.setCursorPos(3,1)


  • monitor.write("Oxygen Central")


  • monitor.setTextColor(colors.white)


  • monitor.setCursorPos(1,3)


  • monitor.write("Main Control")


  • monitor.setCursorPos(1,4)


  • monitor.write("Oxygen Module")


  • term.setCursorPos(1,1)


  • print("OXYGEN SYSTEMS")


  • while true do


  • redstone = rs.getInput("right")


  • if rs.getInput("right") == true then


  • monitor.setCursorPos(15,3)


  • monitor.setBackgroundColor(colors.lime)


  • monitor.write("ON ")


  • sleep(1)


  • else


  • redstone = rs.getInput("right")


  • if rs.getInput("right") == false then


  • monitor.setCursorPos(15,3)


  • monitor.setBackgroundColor(colors.red)


  • monitor.write("OFF")


  • sleep(1)


  • rednet.open("left")


  • local id, message = rednet.receive()


  • if message == "o1" then


  • monitor.setCursorPos(15,4)


  • monitor.setBackgroundColor(colors.blue)


  • monitor.write("ON ")


  • sleep(1)


  • else


  • if message == "o1n" then


  • monitor.setCursorPos(15,4)


  • monitor.setBackgroundColor(colors.red)


  • monitor.write("OFF")


  • sleep(1)


  • end


  • end


  • end


  • end


  • end

same code on Raw paste data:

term.clear()
monitor = peripheral.wrap("top")
monitor.setBackgroundColor(colors.black)
monitor.clear()
monitor.setTextColor(colors.lightBlue)
monitor.setCursorPos(3,1)
monitor.write("Oxygen Central")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1,3)
monitor.write("Main Control")
monitor.setCursorPos(1,4)
monitor.write("Oxygen Module")
term.setCursorPos(1,1)
print("OXYGEN SYSTEMS")

while true do
redstone = rs.getInput("right")
if rs.getInput("right") == true then
monitor.setCursorPos(15,3)
monitor.setBackgroundColor(colors.lime)
monitor.write("ON ")
sleep(1)
else
redstone = rs.getInput("right")
if rs.getInput("right") == false then
monitor.setCursorPos(15,3)
monitor.setBackgroundColor(colors.red)
monitor.write("OFF")
sleep(1)


rednet.open("left")
local id, message = rednet.receive()
if message == "o1" then
monitor.setCursorPos(15,4)
monitor.setBackgroundColor(colors.blue)
monitor.write("ON ")
sleep(1)
else
if message == "o1n" then
monitor.setCursorPos(15,4)
monitor.setBackgroundColor(colors.red)
monitor.write("OFF")
sleep(1)

end
end
end
end
end

i forgot to mentionate that there is another computer sending those messages, it send message 'o1' when it have a redstone signal and the message 'o1n' when it dont

#5 gustavowizard

  • Members
  • 94 posts

Posted 06 June 2014 - 12:35 AM

Ok i managed to make the 1st and 2nd room work, but when i try to read the 3rd room, it only show the redstone ON/OFF IF the 2nd Room redstone is OFF, lol anybody can help me figger why?

this is the code now:

term.clear()
rednet.open("left")
monitor = peripheral.wrap("top")
monitor.setBackgroundColor(colors.black)
monitor.clear()
monitor.setTextColor(colors.lightBlue)
monitor.setCursorPos(3,1)
monitor.write("Oxygen Central")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1,3)
monitor.write("Main Control")
monitor.setCursorPos(1,4)
monitor.write("Oxygen Module")
monitor.setCursorPos(1,5)
monitor.write("Right Wing")
term.setCursorPos(1,1)
print("OXYGEN SYSTEMS")

while true do

redstone = rs.getInput("right")
if rs.getInput("right") == true then
monitor.setCursorPos(15,3)
monitor.setBackgroundColor(colors.lime)
monitor.write("ON ")
sleep(1)
end

if rs.getInput("right") == false then
monitor.setCursorPos(15,3)
monitor.setBackgroundColor(colors.red)
monitor.write("OFF")
sleep(1)
end

local id, message = rednet.receive()
if message == "o1" and id == 63 then
monitor.setCursorPos(15,4)
monitor.setBackgroundColor(colors.blue)
monitor.write("ON ")
sleep(1)
end

local id, message = rednet.receive()
if message == "o1n" and id == 63 then
monitor.setCursorPos(15,4)
monitor.setBackgroundColor(colors.red)
monitor.write("OFF")
sleep(1)
end

local id, message = rednet.receive()
if message == "o2" and id == 77 then
monitor.setCursorPos(15,5)
monitor.setBackgroundColor(colors.lime)
monitor.write("ON ")
sleep(1)
end

local id, message = rednet.receive()
if message == "o2n" and id == 77 then
monitor.setCursorPos(15,5)
monitor.setBackgroundColor(colors.orange)
monitor.write("OFF")
sleep(1)
end
end

#6 gustavowizard

  • Members
  • 94 posts

Posted 06 June 2014 - 01:19 AM

what happens is that the program only check for the 3rd room (last 2 paragraphs) IF the 2nd room signal is OFF, i know there is something to do with the 'end' on the end of each paragraph, but i dont know what code use instead, i want it to continue to check each IF until the end of the 'while true do' line

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 06 June 2014 - 02:42 AM

For the future gustavowizard please surround your code in [code][/code] tags, as you'll see below it makes the code much more readable and with long code please post it to pastebin; it helps us help you quicker. :)

I'm not too sure the problem is exactly what you think it is. I've added some comments to your code to explain some areas of improvement.
Your Code
as you may have noticed from the comments there is a chance that you're missing the signal from the 3rd room with the calls to sleep, however this would also be the case for the second room. Other than that the only thing I can think is that the 3rd room's ID is not 77, so perhaps check that.

As an extra learning point, here is a rewrite of your code to show how else it could be done, in a more efficient manner.
Rewrite


#8 gustavowizard

  • Members
  • 94 posts

Posted 06 June 2014 - 03:20 AM

hey man thanks for helping, the second code you made works but do not show the current state, just OFF on all, im trying to fix the first code, i removed all the sleep and that line you marked, im still having this problem, it seams that when it gets a rednet message from 1 computer he do not get from the other, like, if the 3rd room is ON i get data from the 1st and 3rd room, but is its off i get data from the 2nd room and the same with 2nd room, if its off i get data from 3rd.. etc...
strange :/

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 06 June 2014 - 03:30 AM

Are we able to see the scripts or the code you're running on your other computers?

#10 gustavowizard

  • Members
  • 94 posts

Posted 06 June 2014 - 04:25 AM

i think its working Ok now, its because the room 2 data seams to take more time to be send, i dont have a clue why lol, im on room 6 now all them get signal back fast on rednet except for room 2, it takes some time :D i guess its Ok since its working, im gonna put the final code on pastebin when its done so people can get it, its a pretty neat program to show each module/room of my Space Station has or no oxygen, the oxygen detector send a redstone signal to the computer (in each room) that send message (ON/OFF) to a main host computer on my station control room :D (im using galacticraft and IC2 too with a nuclear reactor)

#11 gustavowizard

  • Members
  • 94 posts

Posted 06 June 2014 - 09:27 AM

thanks a lot for the help guys! :D

here the program ready to use:

http://pastebin.com/W45Wedj2

Edited by gustavowizard, 06 June 2014 - 09:29 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users