|
| 24 Mar 2015 06:03 PM |
I want to do this without any loops.
test = "empty" test.Changed:connect(function() print(test) end)
test = "variable" ===> variable
Something to do with coroutines maybe? |
|
|
| Report Abuse |
|
|
Stefan631
|
  |
| Joined: 23 Dec 2010 |
| Total Posts: 1350 |
|
| |
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 24 Mar 2015 06:04 PM |
| Value objects (StringValue, IntValue, etc) have a Changed property that work exactly like that. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Mar 2015 06:05 PM |
| You could either be efficient (do something after you change it directly) or be inefficient and have it automatic (and won't work with local variables). |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2015 06:06 PM |
Stephan, you intrigue me. Tell me more about these metatables... |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 24 Mar 2015 06:10 PM |
| Metatables are the closest thing to full-on OOP in Lua. They're a headache to get into but they're useful. http://wiki.roblox.com/index.php?title=Metatable |
|
|
| Report Abuse |
|
|
Stefan631
|
  |
| Joined: 23 Dec 2010 |
| Total Posts: 1350 |
|
|
| 24 Mar 2015 06:11 PM |
http://wiki.roblox.com/index.php?title=Metatable http://wiki.roblox.com/index.php?title=Metamethods http://wiki.roblox.com/index.php?title=Metamethods#index |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Mar 2015 06:13 PM |
| metatables are not going to really help, __newindex is a fallback and you can't set an env to a userdata so a fake table solution would have to be done but won't prevent table.insert/rawset :(( |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2015 06:17 PM |
The easiest thing to do (and without metatables) would be something like this:
local var = 5
function changeVar(newval) var = newval --Other code to run end
Just make sure you remember to use changeVar to set it instead of the = |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 24 Mar 2015 06:20 PM |
| @kingkiller1000 I've tried to do this so many times and never though of that. You're an absolute genius. |
|
|
| Report Abuse |
|
|