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 » Scripters
Home Search
 

Re: Metatables

Previous Thread :: Next Thread 
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
30 Nov 2010 08:30 PM
(I know help requests here aren't allowed, SORRY! But it seems the current online population of SH don't know them very well. If you are mad at me for posting this, DON'T POST, JUST LET IT DIE.)


Lets say I have this script-

function m()
return setmetatable({}, {
__index=function(self,ind)
-- ..
end

doFunc=function(arg)
print(arg)
end

})


Now if I did this-
print(m().doFunc("hello world!"))

...it errors. Anyway I can fix this?

[I included '__index' incase thats what I need to fix it.]


Any help would be GREAT!
Thanks!
Report Abuse
Ozzypig is not online. Ozzypig
Joined: 27 Mar 2008
Total Posts: 4906
30 Nov 2010 08:37 PM
I think you're over-thinking it, actually. What are you making metatables for?
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
30 Nov 2010 08:42 PM
Well I'm not quite done with the full script, and thats only a fragment for example purposes.
I'm making a custom hint function.
I'm expecting it to be more powerful than normal hints.
Like-
- When you create one in the Workspace, it is copied to all players.
-- then when you change its text, it coordinates all those hints (which all have an id number)
- Or if you create one in a player, it goes only to that player

And some other stuff I'm gonna script later. But I need to figure this out...
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
30 Nov 2010 09:37 PM
Well... anyone who can provide some sort of help??
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
30 Nov 2010 09:43 PM
I feel like any normal scripter would realize you are totally over complicating that.

Just make a function...
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
30 Nov 2010 09:44 PM
NO ONE.
USES.
METATABLES.

Just stick with normal table- OMG

What if I attachached a metatable to Table(t) and game.Selection:Set(t)

EPIKAL HAX
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
30 Nov 2010 09:49 PM
Ok, here's the actual return statement in my script-


return setmetatable({}, {

__index=function(this,ind)
if ind:lower()=="hint" then return h end
if ind:lower()=="id" then return tonumber(prop.Name:sub(6)) end
if ind:lower()=="text" then return prop.Text end
if ind:lower()=="name" then return prop.Name end
end,



__newindex = function(this, ind, val)
if ind:lower()=="text" then
prop.Text=tostring(val)
for i,v in pairs (game.Players:getPlayers()) do
if v.Name:sub(6)==hold.Name:sub(6) then
v.TextLabel.Text = tostring(val)
end
end
pcall(function() game.StarterGui[hold.Name].TextLabel.Text = tostring(val) end)
return
end
error("Error: cannot create new indexes")
end,

__tostring = function(object)
return object.Name .. " & TEXT= "..object.Text
end,

__metatable = function() end,

remove = function()
for i,v in pairs (game.Players:getPlayers()) do
if v.Name:sub(6)==hold.Name:sub(6) then
v.TextLabel.Text = tostring(val)
end
end
end

})





If I'm still over-complicating, please tell me HOW.
I wanted 'remove' to be called like this- "OBJECT.remove()" or similar.
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
30 Nov 2010 09:50 PM
@Arceus

Normal tables don't have metamethods.

With a metatable, I can lock the ability to create new indexes. So "SOMEMETATABLE.aNewIndex = "value" " Would error.

But if I used a normal table, then that wouldn't error. I don't want that.
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
30 Nov 2010 10:04 PM
@Arceus,

I use metatables, he uses metatables, they ARE useful.
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
30 Nov 2010 10:09 PM
@nom, check your other thread?
Report Abuse
oysi93 is not online. oysi93
Joined: 27 Apr 2008
Total Posts: 12469
01 Dec 2010 07:28 AM
local Methods = {Remove = function(Self) print("Removing...") end}

local Object = setmetatable({}, {
__index = function(Self, Ind)
if Methods[Ind] then
return function() Methods[Ind](Self) end
else
-- Do other index stuff --
end
end
-- Add more metamethods
})

Object:Remove() --> Removing...
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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