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

[Lua][Question] Array's and Tables

Started by Mattzz, 18 March 2012 - 08:46 AM
Mattzz #1
Posted 18 March 2012 - 09:46 AM
Hello sorry if this has been answered or something else (link me or something if it answeres ALL my questions(not many)
okay onto buisness
What are the commands for Arrays and Tables and how I use them (examples?)
thanks in advance

Mattzz
natedogith1 #2
Posted 18 March 2012 - 09:54 AM
http://lmgtfy.com/?q=lua+manual
Mattzz #3
Posted 18 March 2012 - 10:00 AM
NO just no i want the cc commands im already on the 5.1 manual and i dont get it, thats why i posted. also i hate lmgtfy :D/>/>

EDIT: by command i mean functions >.>
Mattzz #4
Posted 18 March 2012 - 10:02 AM
OH NO you read that >.>

can this post (not thread) get a delete please?
Liraal #5
Posted 18 March 2012 - 10:11 AM
okay, i actually had some trouble pasting commands :D/>/>

basically table=array
commands:
table.insert(table,[pos],value) pos default is last element
table.remove(table, [pos]) pos default is last element
table.sort(table)
table.concat(table,[sep]) idk if this works

for quick iteration you can also use pairs(table) which is used like:
for i,j in pairs(table) do
print("Line #"..i..":"..j)
end

you get/set the value of a specific field by table[fieldname] where fieldname is usually (but not always :)/>/> ) a number, e.g. t[1]="abc"

that is about it. Do you want to know something more specific?

BTW, I'm not that awesome, there are many others better than me.
Mattzz #6
Posted 18 March 2012 - 10:16 AM
BTW, I'm not that awesome, there are many others better than me.

BS, stop being so modest :D/>/>
Sebra #7
Posted 18 March 2012 - 10:56 AM
Most thing needed is:

arr={}                   -- arr becomes a table
i=5
arr[i]=val              -- arr got a field 5 with value val
arr["black"] == arr.black  -- it is just the same
p.s. someone should definitely repair this post form :D/>/>
Espen #8
Posted 18 March 2012 - 12:49 PM
Most thing needed is:

arr={}				   -- arr becomes a table
i=5
arr[i]=val			  -- arr got a field 5 with value val
arr["black"] == arr.black  -- it is just the same
p.s. someone should definitely repair this post form :)/>/>
I don't get it, how do you mean "most thing needed"? The code you typed is already possible.
And what do you mean with repairing "post form"? :D/>/>
Mattzz #9
Posted 19 March 2012 - 05:33 AM
Thanks Everyone for all your help. I'm going to look through some code and that should help.
Thanks

Mattzz
Sebra #10
Posted 19 March 2012 - 05:48 PM
I don't get it, how do you mean "most thing needed"? The code you typed is already possible.
It is easiest commands for tables/arrays. :)/>/>
And what do you mean with repairing "post form"? :)/>/>
When I set cursor by mouse and press ctrl-v text inserted in wrong place. Mouse selection is also buggy. :D/>/>
Espen #11
Posted 19 March 2012 - 08:11 PM
When I set cursor by mouse and press ctrl-v text inserted in wrong place. Mouse selection is also buggy. :D/>/>
Hmm, I don't have any problem with it. I think that might depend on what browser you use and if you've enabled JavaScript for this forum.