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: Table Manipulation

Previous Thread :: Next Thread 
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
25 Mar 2015 03:03 PM
I was just wondering if there is any way to fire a function when a table is changed (a value is added or removed).
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
25 Mar 2015 03:04 PM
I don't think so... It wouldn't be usefull anyway since you can only use tables in one script...
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:06 PM
This can be accomplished using metamethods and possibly a wrapper for your table.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
25 Mar 2015 03:11 PM
-- Example

function createObj(tab)
tab = tab and tab or true and {}
tab.Changed = LoadLibrary'RbxUtility'.CreateSignal()
local userdata = newproxy(true)
local metatab = getmetatable(userdata)

metatab.__index = function(s, i)
return tab[i]
end

metatab.__newindex = function(s, i, v)
if i ~= 'Changed' and tab[i] ~= v then
tab.Changed:fire(i, v)
return tab[i]
end
end

return userdata
end

local tab = createObj()
tab.Changed:connect(function(i,v) print(i, v) end)
tab.lol = 3
Report Abuse
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
25 Mar 2015 03:28 PM
It's useful, btw.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Mar 2015 04:00 PM
"tab = tab and tab or true and {}"
Please do not do that.

tab = tab or {}
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