Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How make a metatable variable return an Instance?

Asked by 10 years ago

How would I make the Metatable variable return something other than the table?

Example = setmetatable({}, {
    __index = function(self, i)
        return workspace
    end
})

print(Example) 

Like to make Example return a instance

2 answers

Log in to vote
0
Answered by
Bebee2 195
10 years ago

In your instance, You would do

print(Example.someObscurlyNilIndexThatWillMakeTgisReturnWorkspace)
0
I need the variable of Example return something other than a table... toshir0z 0 — 10y
0
Can you explain further what you are trying to do? Bebee2 195 — 10y
0
Because, http://puu.sh/8aG3t.txt I cannot use just the variable of a created object to parent a object to it.... toshir0z 0 — 10y
0
So I'm not entirely understanding so bare with me. When you call an index from ObjectController... It returns something like a property, correct? So you want to just return the object instead...? Bebee2 195 — 10y
View all comments (6 more)
0
In this case Instance.new("Part").Parent = Instance.new("Part") errors due to the metatable variable returning a table value. I was wondering if it was possible to change it so the variable doesn't return a table but a Instance/Userdata instead. toshir0z 0 — 10y
0
Heh... I'm sorry to say this but ROBLOX limitations with what they lock does not allow this to happen. You have to probably add another index to the object that is equal to the Instance. Bebee2 195 — 10y
0
Meh, I guess I will have to custom code my own fenv... Wish me luck I'm going in deep i~i toshir0z 0 — 10y
0
Are you asking for a way to create a userdata? Use newproxy. Articulating 1335 — 10y
0
Can I point said userdata to an Instance :D? toshir0z 0 — 10y
0
Well, what he is doing is creating a kind of replacement for the Instance table with metatable extensions. If anyone knows a solution, give a call. Bebee2 195 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You cannot do this. However, if you supply a __call metamethod that returns your instance, you can use Example() to get the instance.

Example = setmetatable({}, {
    __index = workspace,
    __call = function() return workspace end
})

print(Example())
--> Workspace 

We used to be able to edit the metatables of in-game objects, but they have been locked for a very long time.

Edit: Alternatively, you can check out my small project and see if it suits your needs.

0
Not practical for my purpose of needing it. toshir0z 0 — 10y
0
You can take my Custom Hierarchy model and see if it suits your needs. AgentFirefox 30 — 10y
0
I just need it for the variable. :/ toshir0z 0 — 10y

Answer this question