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

Modem Transmitting

Started by xtbs, 01 September 2016 - 02:20 AM
xtbs #1
Posted 01 September 2016 - 04:20 AM
Hey everyone, So I am working on a very ambitious warehouse for a couple servers im on, normally I would just use logistics pipes and be done with it, however I wanted to be fancy, this include using a "navigation system" where lights are built into the floor and when locating an item the computer will trigger said lights (which are set in blocks of sorts) and navigate you to your destination, the light part isnt the problem im having, right now I am trying to use a main computer to send a bool variable or even just something to trigger an event on the receiving pc to run its program and activate the lights,

the code I have for the receiving pc is


local modem = peripheral.wrap("right")
modem.open (1)

local event, message = os.pullEvent("modem_message")
if message == 1 then
redstone.setOutput("left", true)
redstone.setOutput("front", true)
sleep(.1)
redstone.setOutput("left", false)
redstone.setOutput("front", false



the code for the master pc is

local modem = peripheral.wrap("back")
modem.transmit (1, 1, 1)



So the end result as of right now, the receing pc program ends but there is not output to start my redstone monstrosity.
also as a side note, this is just a test program to make sure it works the rest of the program will be done up later, more looking at this as a test for the functions later on.

any input is greatly appreciated.
Bomb Bloke #2
Posted 01 September 2016 - 06:23 AM
You've got the event structure wrong; "message" will be a string with the text "right". See the example here, though you may be better off switching to the rednet API instead.

At some point you'll also want to add a loop to your code, such as a "while true do" block (which'll repeat the code contained within it indefinitely). Take a read through this tutorial if you're unfamiliar with looping.
Anavrins #3
Posted 01 September 2016 - 06:25 AM
Quick look at the wiki shows that os.pullEvent("modem_message") returns six arguments, and not two.
http://www.computerc..._message_(event)
Change local event, message = os.pullEvent("modem_message")
into
local event, side, chan, reply, message = os.pullEvent("modem_message")
Edited on 01 September 2016 - 04:26 AM
xtbs #4
Posted 02 September 2016 - 04:35 AM
Im familiar with most things with programming, loops etc. however i dont know much about the apis for cc. and would rednet api work for sending to single computers? because if it just broadcasts to all of them that are open then that wont work too well for me. if it works sort of like the channels with the modem api then i can make it work.
KidBrine #5
Posted 02 September 2016 - 05:15 AM
if you get an error on the line that contains local event, message = os.pullEvent("modem_message") try rednet.recieve()
if you want a specific set of computers to be allowed use


while true do
  local Var1, Var2 = rednet.recive()
  If Var1 == ID1 or Var1 == ID2 then
    break
  end
end
-- do stuff

This will make it so that if the id is not on that list you have set with if Var1 == ID1 or Var1 == ID2 then the code repeats but if it is one of those then it breaks the while true do loop and contiues on witht the code
Edited on 26 January 2017 - 06:30 PM
Bomb Bloke #6
Posted 02 September 2016 - 06:40 AM
Long story short, there's more to the rednet API than "rednet.broadcast()". I suggest reading the documentation I linked earlier, especially the page for "rednet.send()".