|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Nov 2010 09:37 PM |
| Well... anyone who can provide some sort of help?? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 30 Nov 2010 10:09 PM |
| @nom, check your other thread? |
|
|
| Report Abuse |
|
|
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 |
|
|