|
| 13 Aug 2011 04:45 PM |
To have a specified function fire when a string gets changed? For example:
local x = "wut" print(x) x = "lol"..x (function activates now but without me manually calling it)
??? |
|
|
| Report Abuse |
|
|
NeodAemon
|
  |
| Joined: 30 Jul 2010 |
| Total Posts: 89 |
|
|
| 13 Aug 2011 04:50 PM |
| Gotta ram it hard with your pinga. |
|
|
| Report Abuse |
|
|
belial52
|
  |
| Joined: 10 Oct 2009 |
| Total Posts: 8074 |
|
| |
|
| |
|
bombpaw
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 3484 |
|
|
| 13 Aug 2011 04:52 PM |
You missed scripting helpers by a mile >.>
~(°_o) Herpus Derpus~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 04:53 PM |
| Scripting Helpers doesn't know anything. |
|
|
| Report Abuse |
|
|
gz4
|
  |
| Joined: 23 May 2011 |
| Total Posts: 60 |
|
| |
|
NeodAemon
|
  |
| Joined: 30 Jul 2010 |
| Total Posts: 89 |
|
|
| 13 Aug 2011 04:55 PM |
| The concat_shoveyourpinga in it. |
|
|
| Report Abuse |
|
|
bombpaw
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 3484 |
|
|
| 13 Aug 2011 04:55 PM |
Fine.....
Variable = 0 coroutine.resume(coroutine.create(function() local old = Variable while wait() do if old~=Variable print(Variable) old = Variable end end end))
~(°_o) Herpus Derpus~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 04:57 PM |
Hmm... what if I completely changed the string?
x = "wat" x = "lol" (function still fires) |
|
|
| Report Abuse |
|
|
bombpaw
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 3484 |
|
|
| 13 Aug 2011 04:58 PM |
Mine would, their's wouldn't
~(°_o) Herpus Derpus~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 04:58 PM |
Late post.
@Bomb
Does there happen to be a more efficient way? Like, something built into Lua? |
|
|
| Report Abuse |
|
|
elucidir
|
  |
| Joined: 08 Aug 2011 |
| Total Posts: 243 |
|
|
| 13 Aug 2011 04:59 PM |
| If x is a global variable, you could add a __newindex metamethod to the metatable of the function environment. |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 05:01 PM |
@elucidir
Ah, thanks. Didn't think of doing that. |
|
|
| Report Abuse |
|
|
bombpaw
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 3484 |
|
|
| 13 Aug 2011 05:02 PM |
Or that....
~(°_o) Herpus Derpus~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 05:02 PM |
| Wait, does __newindex also fire when a variable is overwritten? |
|
|
| Report Abuse |
|
|
bombpaw
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 3484 |
|
|
| 13 Aug 2011 05:09 PM |
Yes, and when a variable is created,
It is triggered by EVERY global variable.
~(°_o) Herpus Derpus~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 05:10 PM |
Woah...
I never thought to use the function environment like that... |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 05:14 PM |
"Workspace.WiseBot:1: cannot change a protected metatable"
Damn! |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 05:16 PM |
| Any other ways besides locked metatables? |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 13 Aug 2011 05:26 PM |
| Just set the current environment to a new one, cloning all the old members. Then you can have an unlocked environment metatable, theoretically. |
|
|
| Report Abuse |
|
|
elucidir
|
  |
| Joined: 08 Aug 2011 |
| Total Posts: 243 |
|
|
| 13 Aug 2011 05:28 PM |
local q = getfenv() setfenv(1,setmetatable({},{ __index = q, __newindex = function(t,k,v) if k == "x" then print(v) else q[k]=v end end}))
x="hello" |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
elucidir
|
  |
| Joined: 08 Aug 2011 |
| Total Posts: 243 |
|
|
| 13 Aug 2011 05:48 PM |
| That script was just to show how to replace the metatable to detect overwriting. He would need to modify it to retrieve the value. |
|
|
| Report Abuse |
|
|