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

Sensor Kits

Started by GamerNebulae, 07 August 2013 - 10:35 AM
GamerNebulae #1
Posted 07 August 2013 - 12:35 PM
Dear reader,

I have worked a bit with the Nuclear Information Reader and it came to my attention that you actually always use the same variable for the information. For exmaple: to retrieve the data, you use this piece of code all the time:


NIR = peripheral.wrap("left")
a, b, c, data = NIR.get(1)

for i,j in pairs(data) do
  print(i..": "..j)
end

What are the a, b, c values for then? I found this piece of code somewhere on YouTube and have been modifying it a little to my likings, but for all the sensor kits, it seems to be same value to use. I thought the value a would be for the Liquid Sensor Kit for example.
CraftedCart #2
Posted 13 August 2013 - 06:20 AM
I'm not 100% sure but it looks like they are just placeholder variables. I think because you need the "data" variable, the 4th variable for the NIR.get(1), you need to just fill in variable 1, 2 and 3 (which is a, b, c) so you can get the 4th one. Sorry if this is confusing, but with the piece of code you have, it looks like you don't need it.
GamerNebulae #3
Posted 13 August 2013 - 06:28 AM
I'm not 100% sure but it looks like they are just placeholder variables. I think because you need the "data" variable, the 4th variable for the NIR.get(1), you need to just fill in variable 1, 2 and 3 (which is a, b, c) so you can get the 4th one. Sorry if this is confusing, but with the piece of code you have, it looks like you don't need it.

I always found that strange :P/> But thanks anyway. I now know that all Sensor Kits use the same variable to retrieve the table of data.
albrat #4
Posted 13 August 2013 - 01:15 PM
you could technically just use _,_,_,data = NIR.get(1) which just stores the first three varibles in _ (which means we do not intend to use them)

I have recently started to use _ for values I do not intend to use / do not need to use, as assigning a varible to it can get confusing if you need a varible later in your script, eg. a , b, c.
LordIkol #5
Posted 13 August 2013 - 01:50 PM
Hi GamerNebulae,

The Answer to your Question can be found here: (http://www.computercraft.info/forums2/index.php?/topic/4587-cc153mc152-miscperipherals-33/)

When you scroll down to Nuclear Information Reader you find this.

Spoiler
  • get(slot): Gets information from the sensor cards in the specified slot (first slot is 1, second is 2…). Returns:
    • Card UUID (uniquely identifies the card's type) or nil if invalid card
    • Card state, OK means everything is right
    • Card title, as given in the Information Panel GUI
    • Table with the card information

That means if you Use get(slot) you always get 4 Variables back, cause the API is Designed like this.
1st variable contains UUID
2nd variable contains the card state
3rd Variable contains the card title
4th variable contains a table with the card information.

you can name them all 4 however you like if a,b,c,data or q,w,e,r does not matter.
the 4th one will always contain your data and if you need the data you have to use 4 variables.

on the other side if you only need the UUID you could use only one variable cause the UUID is the first entity returned.
if you need card title only you can use only 3 variables and so on.

I hope this helps you to understand that thing a bit better.

Greets
Loki
immibis #6
Posted 14 August 2013 - 04:02 AM
If you really don't want to use extra variables, you can use

data = select(4, NIR.get(1))
but it's harder to understand what this does if you're reading the code.
LordIkol #7
Posted 14 August 2013 - 06:34 AM
If you really don't want to use extra variables, you can use

data = select(4, NIR.get(1))
but it's harder to understand what this does if you're reading the code.

ah nice tip didnt know that.
albrat #8
Posted 14 August 2013 - 03:51 PM
If you really don't want to use extra variables, you can use

data = select(4, NIR.get(1))
but it's harder to understand what this does if you're reading the code.

without really knowing the function of select () I can guess by the name and varibles that it is selecting the 4th data in NIR.get(1) so it's self explanitary, even written in code… So not as hard to understand in code as _,_,_,data = NIR.get(1) (which holds no self - discritiveness… :D/>