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: Is it possible...

Previous Thread :: Next Thread 
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
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 is not online. NeodAemon
Joined: 30 Jul 2010
Total Posts: 89
13 Aug 2011 04:50 PM
Gotta ram it hard with your pinga.
Report Abuse
belial52 is not online. belial52
Joined: 10 Oct 2009
Total Posts: 8074
13 Aug 2011 04:51 PM
^^^
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 04:51 PM
Seriously.
Report Abuse
bombpaw is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 04:53 PM
Scripting Helpers doesn't know anything.
Report Abuse
gz4 is not online. gz4
Joined: 23 May 2011
Total Posts: 60
13 Aug 2011 04:53 PM
The __concat metamethod
Report Abuse
NeodAemon is not online. NeodAemon
Joined: 30 Jul 2010
Total Posts: 89
13 Aug 2011 04:55 PM
The concat_shoveyourpinga in it.
Report Abuse
bombpaw is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 04:57 PM
Hmm... what if I completely changed the string?

x = "wat"
x = "lol"
(function still fires)
Report Abuse
bombpaw is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
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 is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 05:01 PM
@elucidir

Ah, thanks. Didn't think of doing that.
Report Abuse
bombpaw is not online. bombpaw
Joined: 15 Mar 2009
Total Posts: 3484
13 Aug 2011 05:02 PM
Or that....

~(°_o) Herpus Derpus~
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 05:02 PM
Wait, does __newindex also fire when a variable is overwritten?
Report Abuse
bombpaw is not online. 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
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
13 Aug 2011 05:10 PM
Woah...

I never thought to use the function environment like that...
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 05:14 PM
"Workspace.WiseBot:1: cannot change a protected metatable"

Damn!
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
13 Aug 2011 05:16 PM
Any other ways besides locked metatables?
Report Abuse
LPGhatguy is not online. LPGhatguy
Forum Moderator
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 is not online. 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 is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
13 Aug 2011 05:41 PM
[ Content Deleted ]
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
13 Aug 2011 05:43 PM
[ Content Deleted ]
Report Abuse
elucidir is not online. 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
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