Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 04:59 PM |
Say I created a table:
table = {}
And then I insert something into the table:
table.insert(table,'blue')
And then I have another function that searches thru the table:
function findthing(thing)
for i,v in ipairs(table) do if v[1] == thing then return v end end
Wut happens if I do:
table[1] = table[1] + 1
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 12 Nov 2016 05:00 PM |
It would try to do `'blue' + 1` and error.
|
|
|
| Report Abuse |
|
|
|
| 12 Nov 2016 05:01 PM |
| If table[1] is a number, for example 5. table[1] will be 6. If it is a string, you'll get an error. |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:02 PM |
| Alright how about table[1][1] |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 12 Nov 2016 06:03 PM |
| I don't think multidimensional arrays work in rbxlua |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:09 PM |
| Well it can compare table[1][1] > table[1][2] just playing around, wut is this even? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 06:14 PM |
tbl[1] == "blue" ("blue")[1] = nil |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:41 PM |
OH THX, that makes a lot more sense, so say if i have
table={'blue'}
blue={'lolz'}
then
table[1][1]
would be
blue + lolz
? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 06:43 PM |
no
local tbl = { { 123 } } print(tbl[1][1]) -->123 |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 06:43 PM |
or in your case
blue={'lolz'} tbl={blue} -- notice, no quotation marks here
print(tbl[1][1]) --> lolz |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 12 Nov 2016 06:45 PM |
> ("blue")[1] = nil
Wait, why doesn't it crash? |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:46 PM |
| Another question, how do you make animations for the new rig. |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
| |
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:47 PM |
| Becuz, I didn't script it in, just questions. |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:55 PM |
alright now,
say i did
table.insert(table,("Really Red",1))
so thats mean that it produces a table that looks like this right
table = {{"Really Red", 1}} |
|
|
| Report Abuse |
|
|
Azodon123
|
  |
| Joined: 05 Apr 2012 |
| Total Posts: 140 |
|
|
| 12 Nov 2016 06:58 PM |
and therefore if I did
table.insert(table,("Really Blue", 1))
the table would look like
table = {{"Really Red", 1}{"Really Blue", 1}}
and therefore if I did
table[1][2]+1
the table would look like
table = {{"Really Red", 2}{"Really Blue", 1}} -- after really red, 1 changed to 2 |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 12 Nov 2016 07:06 PM |
You might want to try running that code :) table is a library, don't insert stuff there. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 07:08 PM |
"Wait, why doesn't it crash?" Because strings have a metatable, the __index field is set to the string table.
"table.insert(table,("Really Red",1))
so thats mean that it produces a table that looks like this right" No, you'd have to do
table.insert(tbl, {"Really Red", 1}) |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 12 Nov 2016 07:17 PM |
>Because strings have a metatable, the __index field is set to the string table. Wait, strings are tables, not arrays? How the hell does it work? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 07:19 PM |
They're neither tables nor arrays in Lua. It's just that you can assign a metatable to pretty much anything.
All strings have the same metatable for example, which is what makes stuff like ("abc"):sub(1, 2) possible. |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 12 Nov 2016 07:26 PM |
>It's just that you can assign a metatable to pretty much anything. You can? Just tried assigning a metatable to a number, didn't work :\ |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 07:28 PM |
Because the setmetatable function only handles tables and strings. Try this (outside of Roblox obviously)
debug.setmetatable(0, { __index = { sqr = function(s) return s^2 end } }) print((10):sqr()) -->100 |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 12 Nov 2016 07:48 PM |
| So there's a single metatable per type for all types except tables and userdata, okay. TODO: find a way to use this for shenanigans |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2016 07:50 PM |
| Well no, just strings. But you can manually add them using debug.setmetatable to pretty much all types. |
|
|
| Report Abuse |
|
|