Just as a point of learning for you in Lua you can define multiple variables on a single line, for example like so
local sChannel, rChannel = 1, 2
Also this means you could condense these
local event
local sModemSide
local sChannel
local replyChannel
local message
local sDistance
local analogNumber
local bundledNumber
local rsState
local i
local x
local y
local bool1
local bool2
local serializedInfo
to this
local event, sModemSide, sChannel, replyChannel, message, sDistance, analogNumber, bundledNumber, rsState, i, x, y, bool1, bool2, serializedInfo
and it will still mean that all these variables are initialised in the local scope.
Other points that could be made are with the addBools function
local function addBools(bool1,bool2)
if bool1 or bool2 then
return true
else
return false
end
end
this is one area that always annoys me when people do it, a conditional statement resolves to a boolean so it knows which branch to execute, so having a conditional that then just returns a boolean is pointless, just return the conditional
local function addBools(b1, b2)
return b1 or b2
end
I'm glad to see that you're making use of local variables and functions, it's very rare to see in new programmers!
Other points I wish to bring up is any variables that are defined in a function's signature are already local meaning they are not required to be defined elsewhere
the following is pointless unless you plan on using x,y elsewhere, in which case inside the function `foo` there will be a naming conflict if you wish to use the x/y from the scope above.
local x, y
local function foo(x,y)
print(x,y)
end
the same also applies for, for loops... the variable defined in the for loop initialiser is localised to that loop.
it should be noted that this
local rs_info = {bundled,analog,state,ID}
is equivalent to this
local rs_info = {}
since the variables inside the table constructor are nil variables. did you mean to initialise keys here?
second to last, you should also attempt to check if the peripheral on the given sides are actually modems before wrapping them, with
peripheral.getType
Lastly, it should be noted that if you don't wish to accept a return value (after the one you want) you don't have to, it should also be noted that it is general convention for variables you wish not to use are named with _ for example this
event,sModemSide,sChannel,replyChannel,message,sDistance = os.pullEvent("modem_message")
could become this
_, _, _, _, message = os.pullEvent("modem_message")
which makes it much easier for you to see what variables you're wanting... obviously this all comes down to style though.
Overal a good program/api, just a few places that could do with some "spit and polish". I hope everything I've covered above makes sense and helps you in your future programmes.
Edited by theoriginalbit, 14 December 2013 - 01:58 AM.