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

RedNetLog

Started by MisterMeister32, 24 March 2018 - 01:20 PM
MisterMeister32 #1
Posted 24 March 2018 - 02:20 PM
RedNetLog


RedNetLog is a very basic and easy-to-use RedNet Logger.

It is a useful tool for developng and debugging networking applications.

Download:

pastebin get wCBNGPiy rnlog

Output format: ID(Protocol):Massage

Coming Features:
  • Saving logs to a File
  • Fanzy GUI
CLNinja #2
Posted 24 March 2018 - 02:36 PM
This sort of thing has been done time and time again. I really don't think we need another one.
SquidDev #3
Posted 24 March 2018 - 03:01 PM
This sort of thing has been done time and time again. I really don't think we need another one.
You could say that about many CC programs though. Looks at the Operating Systems section.

MisterMeister32: this is actually pretty decent code for a first program, good job! One thing I'd recommend is prefixing all your variable definitions with "local". It's a rather trivial change, but means values are specific to a given function, rather than leaked across programs. So you'd change your code to look something like:

local function open() --# Note the "local function" instead
  local p = peripheral.getNames() --# Again, note the use of local when declaring the variable.
  local modem = nil
  for i = 1, #p do --seaching for modems
    if peripheral.getType(p[i]) == "modem" then
      modem = p[i] --# As we're setting an existing variable, we don't need it here.
    end
  end

There's also a neat little trick you can do with peripheral.find in order to open all modems. Instead of looping through each modem and opening it, you can do:

peripheral.find("modem", rednet.open)
MisterMeister32 #4
Posted 24 March 2018 - 03:50 PM
Now I put "local" before every function and variable.
I didn't knew about peripheral.find, but leave my own routine In there, because its easier to work with.