Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
deadpangod3

Modem causing a syntax error in print()

Question

Hi! My program seems to think that any print statements that come after my code to receive modem signals, despite being correct, still result in  syntax errors, while any that come before are completely fine. It doesn't matter if it's a variable, a number, or a string. It affects term.write(), and io.write() too.

The goal of this program is to be a hub of sorts where I can remotely send commands to robots to do assigned tasks, but that obviously requires being able to send signals to them. So I was experimenting with it to learn, however, I have not been able to solve this issue. I have experimented with this a ton and narrowed it down to the code that receives the signal, as soon as that is removed, the print statements work fine. I'm hoping someone can tell me how and why this is happening.

The Error:

2019-07-03_17_13_15.thumb.png.41d8c380906e016bcc46bf17ed480662.png

 

The Hub program:

local os = require("os")
local component = require("component")
local event = require("event")
local computer = require("computer")
local term = require("term")

local modem = component.modem
local Robots = 1
local Openport = 2
local modemaddress = component.get("d25")
local shutdown = false
local message

modem.open(1)
modem.setStrength(20)
print("port is opened:" .. tostring(modem.isOpen(1)))


local function Recieve()
  local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
  print("Received data '" .. tostring(payload) .. "' from address " .. remoteAddress .. " on network card " .. localNetworkCard .. " on port " .. port .. ".")
  print(payload)
  message = tostring(payload)
end

event.listen("modem_message", Recieve)

while(shutdown == false) do
  if(message == "Signal Test.") then
    broadcast(1, "Signal Test Reply.")
  end
  term.clear
  print(computer.uptime())
end

It's far from finished so some variables are unused at the moment, sorry if it grinds your gears.

The other computer which is acting as a test broadcaster has this program running to broadcast to the main computer, this has been working so far:

local width = 4
local height = 13
local length
local posx
local posy
local posz
local os = require("os")
local component = require("component")
local modem = component.modem
local modemaddress = component.get("68e")
local event = require("event")

modem.open(1)
modem.setStrength(20)
modem.broadcast(1, "Signal Test.")
modem.send(modemaddress, 1, "Signal Test.")
local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
print("Received data '" .. tostring(payload) .. "' from address " .. remoteAddress .. " on network card " .. localNetworkCard .. " on port " .. port .. ".")

I am also using the addon Computronics, though no parts from it are in either computer.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1

if you dont understand the compile error message (specifically, a lua load error message), then remove code until you pinpoint where the problem.

anyways, `term.clear print("asdf")` is not valid lua, try `term.clear() print("asdf")`

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.