Posted 04 June 2012 - 11:56 PM
Hello all,
Im relatively new to programming with LUA and i was trying to program a network with packet switching and noticed Monochrome
( http://www.computercraft.info/forums2/index.php?/topic/527-packet-switched-networking-cover-big-distances-with-wireless/ )
had already created such a network. As far as i can tell it works extremely well, and now here is my problem. I modified his code to create a new independent network
for tracking information about my railway system and routing railcarts to destinations that i input.
to accomplish this i added a new table that stores a string in the form of <label> ">" <computer ID>
i can get the string to be added to the table with this code
and i can get the string to be added to a packet to be sent to other gateways with this code,
but when i try to process the packet on a gateway it tells me this chunk of code
more specifically
is producing this error
"attempt to perform arithmetic __ sub on nil and number"
and needless to say im at a loss if you feel you need more code to look at to help identify the problem, I'm more than willing to provide it
Im relatively new to programming with LUA and i was trying to program a network with packet switching and noticed Monochrome
( http://www.computercraft.info/forums2/index.php?/topic/527-packet-switched-networking-cover-big-distances-with-wireless/ )
had already created such a network. As far as i can tell it works extremely well, and now here is my problem. I modified his code to create a new independent network
for tracking information about my railway system and routing railcarts to destinations that i input.
to accomplish this i added a new table that stores a string in the form of <label> ">" <computer ID>
i can get the string to be added to the table with this code
--puts the label and id into one string for use with the processing function **CASSEM ADDED**
local function merge_LabelandID(label, id)
str = label .. ">" .. id .. " "
print("Associated label " .. label .. " with " .. id)
Label[id] = str
end
and i can get the string to be added to a packet to be sent to other gateways with this code,
--Adds the label and associated ID to the gwlist
for id3, labels in pairs(Label) do
ret = ret .. labels .. " "
end
but when i try to process the packet on a gateway it tells me this chunk of code
--Process label list **CASSEM ADDED**
pos = 0
for st,sp in function() return string.find(labellist," ",pos,true) end do
entry = string.sub(labellist,pos,st-1) .. ""
-- labels is the label, id is the id with which it's associated
labels = string.sub(entry, 0, (string.find(entry, ">") - 1)).. ""
id = tonumber(string.sub(entry, string.find(entry, ">") + 1))
if (Label[id] == nil)
then
-- Update Label list. We are now dirty
Label[id] = merge_LabelandID(labels, id)
dirty = true
end
pos = sp + 1 -- Jump past current divider
end
more specifically
labels = string.sub(entry, 0, (string.find(entry, ">") - 1)).. ""
is producing this error
"attempt to perform arithmetic __ sub on nil and number"
and needless to say im at a loss if you feel you need more code to look at to help identify the problem, I'm more than willing to provide it