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

x(tArgs[1])

Started by togaboy531, 03 March 2012 - 01:11 AM
togaboy531 #1
Posted 03 March 2012 - 02:11 AM
x(tArgs[1]) what does the one stand for in this? Im guessing its the number of charecters that the argument reads for? and if that is the case, would it matter if there were less than that amount each time an argument was entered?
Advert #2
Posted 03 March 2012 - 02:13 AM
The 1 denotes that you're accessing the first element in the table; you can do this to print all the elemtnts and their keys/indexes:


for k, v in pairs(tArgs) do
 print("Key/index: ", k, "nValue: ", v)
end
togaboy531 #3
Posted 03 March 2012 - 02:16 AM
so if i used x(tArgs[5]) and it tried to read "rageface" it would only get "ragef"? and would it matter if with x(tArgs[5]) trying to read "red"?
MysticT #4
Posted 03 March 2012 - 02:19 AM
It doesn't access the characters of a string, but the values of the table.
A table is something like this:

some_table = { "Hello", 12, "SomeValue" }
so if you do some_table[1] it returns "Hello", some_table[2] returns 12, and so on.
I suppose that tArgs is the table with the arguments passed to the program, so each word you give to the program (using program_name arg1 arg2 …) is a value on that table.
togaboy531 #5
Posted 03 March 2012 - 02:23 AM
Oh alright! I'm not new to LUA but im just new to using it on minecraft, a few of the functions and such isnt what im used to, so its a bit difficult to troubleshoot what im doing…
togaboy531 #6
Posted 03 March 2012 - 02:33 AM
is there a better way to use the text typed into the console as a trigger other than tArgs?
Liraal #7
Posted 03 March 2012 - 06:55 AM
in program? read()/os.pullEvent()