Posted 26 July 2013 - 06:47 AM
Hello all,
I have a little bit of experience with C and Python programming languages but I am just now taking up Lua for use with this mod and peripheral mods. I'm unfamiliar with the "table" data type and I am having trouble accessing data that has been output to a table. I've tried what I know about arrays to access it, since I've read that they're similar to tables, to no avail. I've found the reference manual for Lua at www.lua.org but it's a little too dense for me to effectively find out what I am trying to find out (also, the word table shows up almost 400 times).
What I do know is that in code I have used from elsewhere, a table was accessed as follows:
The get() function is from MiscPeripherals and is essentially just supposed to output the data it gets to a table. So, "data" in this case is a table. Trying to access this table to print out the status of a REC in interactive mode gives me things like this:
So from what I can deduce things like "No Energy" and "Full Energy" act like indices. Is there a way to check out what all of the indices of a table are (if my guess is right)? Also, can tables only hold boolean variables, or can they be an amalgamation of types (like lists in Python)?
I have a little bit of experience with C and Python programming languages but I am just now taking up Lua for use with this mod and peripheral mods. I'm unfamiliar with the "table" data type and I am having trouble accessing data that has been output to a table. I've tried what I know about arrays to access it, since I've read that they're similar to tables, to no avail. I've found the reference manual for Lua at www.lua.org but it's a little too dense for me to effectively find out what I am trying to find out (also, the word table shows up almost 400 times).
What I do know is that in code I have used from elsewhere, a table was accessed as follows:
...
greader = peripheral.wrap("right")
data = greader.get()
while not data["Full Energy"] do
...
The get() function is from MiscPeripherals and is essentially just supposed to output the data it gets to a table. So, "data" in this case is a table. Trying to access this table to print out the status of a REC in interactive mode gives me things like this:
lua> data = peripheral.wrap("right").get
lua> data
table: 56cfad29
lua> data[0]
nil
lua> data[1]
nil
lua> data["Full Energy"]
false
lua> data["No Energy"]
true
So from what I can deduce things like "No Energy" and "Full Energy" act like indices. Is there a way to check out what all of the indices of a table are (if my guess is right)? Also, can tables only hold boolean variables, or can they be an amalgamation of types (like lists in Python)?