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: Detect Change in Variables?

Previous Thread :: Next Thread 
NetherZero is not online. NetherZero
Joined: 25 Apr 2010
Total Posts: 316
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 is not online. Stefan631
Joined: 23 Dec 2010
Total Posts: 1350
24 Mar 2015 06:04 PM
metatables!
Report Abuse
NotAshley is not online. 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 is not online. 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
NetherZero is not online. NetherZero
Joined: 25 Apr 2010
Total Posts: 316
24 Mar 2015 06:06 PM
Stephan, you intrigue me.
Tell me more about these metatables...
Report Abuse
NotAshley is not online. 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 is not online. 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 is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
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 is not online. 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
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