Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function idToLabel(id)
- local computerid = {0, 1, 2} --add more id's here as needed
- local label = {"computer 0's label", "computer 1's label", "computer 2's label"} --change these to match, make sure entry 0 is matches 0 above
- local found = 0
- for n = 0,#computerid do --starting a for loop to check the above array entires from 0 to the number of entries in computerid (#computerid)
- if computerid[n] == id then --when there's a match continue
- name = label[n] --set variable "name" to the value of the matching label
- found = 1 -- placeholder variable to bypass a nil exception
- return name --return the variable name to where it was called from
- end
- end
- if found = 0 then --if no id and matching label are found
- return false -- function returns false value
- end
- end
- rednet.open("top")
- while true do
- id, text = rednet.receive() --simplified, if () has no number the listener stays open
- idtolabel(id)
- if not idtolabel then --this line will check if idtolabel returned false
- print(id .. "> " .. text) --if false instead of using "name" which would be nil, display the id instead
- else --otherwise
- print(name .. "> " .. text) --use the name variable rather than the computer id
- end
Advertisement
Add Comment
Please, Sign In to add comment