Jump to content




Sensor Kits


7 replies to this topic

#1 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 07 August 2013 - 11:35 AM

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.

#2 CraftedCart

  • Members
  • 67 posts
  • LocationUnited Kingdom, Earth

Posted 13 August 2013 - 05: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.

#3 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 13 August 2013 - 05:28 AM

View PostCraftedCart, on 13 August 2013 - 05:20 AM, said:

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.

#4 albrat

  • Members
  • 162 posts
  • LocationA Chair

Posted 13 August 2013 - 12: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.

#5 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 13 August 2013 - 12:50 PM

Hi GamerNebulae,

The Answer to your Question can be found here: (http://www.computerc...peripherals-33/)

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

Spoiler

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

#6 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 14 August 2013 - 03: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.

#7 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 14 August 2013 - 05:34 AM

View Postimmibis, on 14 August 2013 - 03:02 AM, said:

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.

#8 albrat

  • Members
  • 162 posts
  • LocationA Chair

Posted 14 August 2013 - 02:51 PM

View Postimmibis, on 14 August 2013 - 03:02 AM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users