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

Sending commands to other computers

Started by maxo10, 11 December 2017 - 01:59 PM
maxo10 #1
Posted 11 December 2017 - 02:59 PM
So I've tried to make a network (trial and error, so only 2 computers for now), and use 1 main computer to send/transmit commands over the network. But for some reason my modems/computers just stop working, as in, No errors, no yielding error, no nothing and it doesnt loop.
First computer:
Spoiler

local modem = peripheral.wrap("left")
local newScreen = peripheral.wrap("top")
term.redirect(newScreen)
term.clear()
term.setCursorPos(1,1)

modem.open(1)
local event, modemSide, senderChannel,
  replyChannel, message, senderDistance = os.pullEvent("modem_message")

modem.transmit(1, 1, "getEnergyStored")
print("message send")
print(message)
Second computer:
Spoiler
local modem = peripheral.wrap("right")
local newScreen = peripheral.wrap("top")
local capBank = peripheral.wrap("back")
term.redirect(newScreen)
term.clear()
term.setCursorPos(1,1)

modem.open(1)
print("Channel 1 is now opened for listening.")

local function capEnergy()
  return capBank.getEnergyStored()
end

while true do
  local event, message = os.pullEvent("modem_message")
  if message then
	if message == "getEnergyStored" then
	  local energyStored = capEnergy()
	  modem.transmit(1, 1, energyStored)
	end
  else
	print("nothing yet")
  end
end

What am i missing here?

edit:
screenshot:
How the **** do I add a screenshot, its not allowed?
Edited on 11 December 2017 - 02:11 PM
KingofGamesYami #2
Posted 11 December 2017 - 03:21 PM
edit:
screenshot:
How the **** do I add a screenshot, its not allowed?

The forum's entire uploading system is broken(including pictures / attachments). Dan200 is the only one with the authorization necessary to fix it, and he hasn't yet. You can insert a picture by uploading to imgur and using the [img] tags.

---

As for your programs, both wait for a modem message event to occur before sending anything. Since no computer sends a message, they are stuck waiting for one.[/img]
maxo10 #3
Posted 12 December 2017 - 12:26 AM
So they dont timeout? Like other functions gave "no yielding" after awhile. But anyway thanks, will look into it!
CLNinja #4
Posted 12 December 2017 - 12:51 AM
So they dont timeout? Like other functions gave "no yielding" after awhile. But anyway thanks, will look into it!
Pulling events DOES yield, which is the issue. It yields and never returns