I am working with misc peripherals and more specifically the advanced nuclear reader that can hold 9 sensors. I know I can use the getslot() to pull information from the sensor card but I can't find if it possible to write a code that will check if new senors have been added. My goal is to write a program that will detect which slot has a sensor and pull the information off it. This will allow me to add sensor cards as I go and not have to update the program.
In short is there a function that will check all slots and return true or false if a slot as a card in it.
Advance Nuclear Reader — Misc Peripherals addon
Started by Zelman89, Jun 13 2013 02:48 PM
7 replies to this topic
#1
Posted 13 June 2013 - 02:48 PM
#2
Posted 13 June 2013 - 04:14 PM
Split into new topic.
#3
Posted 13 June 2013 - 05:48 PM
You can loop through and check the slot against a known slot or just check the number of items in the slot.
Item count example:
Item count example:
for slot = 1, 16 do if turtle.getItemCount(slot) > 0 then -- Item(s) in slot else -- Empty slot end end
#4
Posted 14 June 2013 - 04:57 PM
dumb question but I am guessing I need a turtle for this function to work or can an advance comp do this too?
#5
Posted 14 June 2013 - 06:11 PM
That code is indeed intended to check the contents of a turtle's inventory. I get the impression the sensors are stored in the reader, so I'm not sure checking the turtle's inventory has any point to it here.
According to the MiscPeripherals thread, get(slot) returns nil if the slot is empty. Hence, if I wanted to check all nine slots from a tier 2 reader, I'd use something like:
There are quite a few other ways this can be done depending on what you want to do with the sensor info and when.
According to the MiscPeripherals thread, get(slot) returns nil if the slot is empty. Hence, if I wanted to check all nine slots from a tier 2 reader, I'd use something like:
(wrap the sensor to "nreader" or somesuch here)
for i=1,9 do
UUID,state,title,cardinfotable = nreader.get(i)
if UUID ~= nil then -- There was something in the current slot, so...
... -- .. do something with that information here.
end -- Otherwise do nothing; check the next slot.
end
There are quite a few other ways this can be done depending on what you want to do with the sensor info and when.
#6
Posted 15 June 2013 - 05:52 PM
Thanks bomb, thats what i as looking for!
#7
Posted 15 June 2013 - 06:17 PM
works perfectly but now is there any way to count how many came back having something in its slot? I tried this:
never mind had a typo somewhere
(wrap the sensor to "nreader" or somesuch here) u = 0 for i=1,9 do UUID,state,title,cardinfotable = nreader.get(i) if UUID ~= nil then print(something) u = u + 1 else u = u end end print(u.."slot in use"
never mind had a typo somewhere
Edited by Zelman89, 15 June 2013 - 06:20 PM.
#8
Posted 15 June 2013 - 06:23 PM
The "else u = u end" bit is redundant and should just be replaced with "end", but otherwise that looks fine.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











