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 » Game Design
Home Search
 

Re: Setting a metatable for a modulescript?

Previous Thread :: Next Thread 
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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 is not online. 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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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 is not online. 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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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 is not online. 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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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
awsomecoolhacker is not online. awsomecoolhacker
Joined: 13 Jun 2010
Total Posts: 158
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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