|
| 03 Oct 2015 09:46 PM |
So, since the code in a module script doesn't execute unless triggered by an external command, I wouldn't be able to do the "setmetatable" function INSIDE the module script, so how would I set the metatable for a module script?
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
larr1212
|
  |
| Joined: 06 Jan 2015 |
| Total Posts: 259 |
|
|
| 03 Oct 2015 09:53 PM |
| You can't set or edit the metatables of instances because they are userdatas and the metatable metamethod is set. |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2015 09:54 PM |
I don't mean the actual module script, I mean the table INSIDE the module script that is returned when you use the "require" function.
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 03 Oct 2015 09:55 PM |
| You should be able to set a metatable inside of a modulescript no problem. A modulescript is ran the first time some other script require()'s it and it runs everything up until it actually returns the module. |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2015 10:13 PM |
I tried the following:
- - - -
local alpaca = {}
setmetatable(alpaca, { __lt = function(alp1, alp2) if type(alp2) == "table" then return alp1.age.Value < alp2.age.Value elseif type(alp2) == "number" then return alp1.age.Value < alp2 end end } )
return alpaca
- - - -
When I tried to compare with the less than operator [if 10 > alpaca then] it gave me an error: attempt to compare table with number. In my metatable, I made it so that if the right side of the comparison was a number, it would compare the number to the "age" property inside the table. I don't think the metatable was set.
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2015 10:19 PM |
EDIT: I meant [if alpaca < 10 then] not [if 10 > alpaca then].
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 03 Oct 2015 10:20 PM |
It's got to be something else. I just ran the following test and got output that proves that you can set a metatable inside a modulescript.
--// Script local module = require(script.ModuleScript) print(module.thing1) print(module.thing7)
--// Module Script local module = { thing = 1, thing2 = 2, thing3 = 3, }
setmetatable(module, { __index = function() print("LOL!") return nil end } )
return module
--// Output LOL! nil LOL! nil |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2015 10:38 PM |
I tried what you just did and not even __index worked. I guess the script must be glitched.
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2015 11:39 PM |
I tried setting the table externally, and it still didn't work. .-.
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|
|
| 04 Oct 2015 12:40 AM |
Actually, now that I tried it, NO metatables work whatsoever, anywhere.
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen |
|
|
| Report Abuse |
|
|