generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Setmetatable question (simple)

Previous Thread :: Next Thread 
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 09:23 PM
Does setmetatable have to be used when trying to use meta tables? for example, if I do this:

local qs = {
q1 = {"hi"} q2 = {"wow"}
}

???
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 09:27 PM
Wtf seriously? You "helpers" can't answer a question as simple as this??? wow.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 09:31 PM
wow bump.
Report Abuse
iimerkingalaxy is not online. iimerkingalaxy
Joined: 23 Sep 2013
Total Posts: 223
20 Jun 2014 10:04 PM
yes its
like this

local x = {}
local metaTable = {}
setmetatable(x, metaTable)
print(getmetatable(x))
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 10:11 PM
You're trying to make a table made of tables?

t = {
a = {7},
b = {8},
c = {9}
}

print(t[a][1])
>7

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:14 PM
I'm trying to make a table of meta tables, then select one random and convert it to a string, but I just wanna know do I have to use set meta table if I' putting multiple tables in?
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:15 PM
scratch that. I'm trying to make a meta table of tables*
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 10:17 PM
Are you talking about creating a table that contains more tables or setting a metatable to a table? Because your original post had nothing to do with metatables, but had everything to do with a table containing tables.

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:22 PM
so basically, I don't have to create a table and a metatable, but instead, I can put make a metatable containing multiple tables? Cause the wiki makes me think I have to use setmetatable everytime cause they use it after after metatable, but I just wanna make a table filled with tables which is a meta table, so I can select on from that table containing multiple tables. Example, would this work?

local tbl = {
q1 = {"wow"} q2 = {"wtf"} q3 = {"moveordie"}
}
local tbl2 = {
a1 = {"omgwtf"} a2 = {"ohcrapcar"} a3 = {"end"}
}

local this = tbl1:GetChildren()
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 10:25 PM
A table filled with tables isn't a metatable, it's multidimensional table, they're COMPLETELY different.

Also, you need more commas
local tbl = {
q1 = {"wow"}, q2 = {"wtf"}, q3 = {"moveordie"}
}
local tbl2 = {
a1 = {"omgwtf"}, a2 = {"ohcrapcar"}, a3 = {"end"}
}

Now you can access whatever you want.

print(tbl[q1][1])
>wow

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 10:26 PM
Also, you can't call :GetChildren() on it, but you could make your own function to do the same

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:26 PM
metatables are for metamethods, search up metatable tutorial, there are some good ones.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:28 PM
I've never heard of multi-dimensional tables, but how would I make the script select a random table? inside the m-dt?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:30 PM
o = {
{5,8,3,5,6,3,"cri"},
{"ho","lol","troll"}
};

print(o[math.random(1,#o)][1])
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 10:30 PM
>Does setmetatable have to be used when trying to use meta tables?

Yes. That's how metatables are made. Otherwise, they're just indices in a table.

> for example, if I do this:
>local qs = {
>q1 = {"hi"} q2 = {"wow"}
>}
>???

There isn't even any meta-methods in this table; meta-methods start with two underscores.

> Wtf seriously? You "helpers" can't answer a question as simple as this??? wow.

I'm sorry, you don't know the answer to this "simple" question, so it's our fault for not catering to your needs instantly? You're not the only one on this forum, and not everyone on this forum is advanced; anyone is allowed to view it. You want help? Don't be rude and get some patience.
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 10:32 PM
I would normally give you some examples and an in-depth explanation of metatables, but you were too arrogant and narcissistic. Look it up on the wiki.
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
20 Jun 2014 10:34 PM
Metatables are tables that define alternate operations for the standard operations on tables. For example, it you say myTable.foo = bar and myTable has a metatable, then if the metatable has a function in it at index "__newindex" then it is called with myTable, "foo", and "bar". Whatever the function does is what myTable.foo = bar does.

Multidimensional tables are simple tables of tables. Each table contains a element for every index, and those elements could be other tables. When I say:
myTable.foo.bar.hat, Lua first gets myTable, finds it's index foo, indexes that result with bar, and that with hat because mytable had a table at index foo, which had a table at bar, which had some value at hat.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:45 PM
@Thenew, If you weren't on the forum when I posted it, why are you getting offended? Fail. And you didn't help at all, gtfo
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:46 PM
i agree with lua, if this is so simple why did you ask?
because its not(for you at least), you should be the one getting out
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:47 PM
Thanks @arb and swim
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:49 PM
@dueling, You just asked if it's so simple why would I ask? You sound dumb.

1) "Multi-Dimensional Tables" were never mentioned or explain on the wiki. They said metatable is a table for tables. It makes no sense to ask why how I didn't know about it due to it's simplicity. I was simply never told about m-dt.
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 10:49 PM
>@Thenew, If you weren't on the forum when I posted it, why are you getting offended? Fail.

Someone replied, it got bumped to the top. That's how the forums work.

>And you didn't help at all, gtfo

Weird... it's almost like I said I wouldn't help in that last reply... Oh wait, I did. "I would normally give you some examples and an in-depth explanation of metatables, but you were too arrogant and narcissistic."

Don't act entitled and expect an answer just because you posted a thread. That's all I am trying to say.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:50 PM
you claimed it yourself.
it's like doing an assignment.
you know the answer, yet you ask others for it.
you seem to be the only dumb one here.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
20 Jun 2014 10:51 PM
dude just shutup ur dumb btw I don't care about how long it took you to type that ur a n0b gtfo slob and that's what the time on the post is for you snail
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:52 PM
lol hes raging now
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image