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 » Scripting Helpers
Home Search
 

Re: variable change event?

Previous Thread :: Next Thread 
xdhunta1774 is not online. xdhunta1774
Joined: 28 Jun 2011
Total Posts: 1112
15 Dec 2011 05:49 PM
[ Content Deleted ]
Report Abuse
xdhunta1774 is not online. xdhunta1774
Joined: 28 Jun 2011
Total Posts: 1112
15 Dec 2011 06:29 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Dec 2011 06:32 PM
A variable in a script?
As in, changing 'lolpwnsause' to 1337?
Report Abuse
xdhunta1774 is not online. xdhunta1774
Joined: 28 Jun 2011
Total Posts: 1112
15 Dec 2011 06:34 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Dec 2011 06:35 PM
Hehe.
Let me do some testing, and I will get back to you.
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
15 Dec 2011 06:37 PM
inb4LotsAndLotsOfMetatables

-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]-
Report Abuse
xdhunta1774 is not online. xdhunta1774
Joined: 28 Jun 2011
Total Posts: 1112
15 Dec 2011 06:38 PM
[ Content Deleted ]
Report Abuse
TwoBoo is not online. TwoBoo
Joined: 08 Feb 2011
Total Posts: 10790
15 Dec 2011 06:38 PM
herp = 0
if herp == 0 then
herp = 1
if herp == 1 then
function lolk()
print("herp")
end
end
end

Idk.
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
15 Dec 2011 06:38 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Dec 2011 07:12 PM
The best you can do is this:


function setVarChangeEvents(LOLEPICSAUCE)
    local function getter() end
    local vars = {}
    local control = setmetatable({}, {__index = function(t, k)
        if vars[k] == nil then
            vars[k] = setmetatable({ Value = v }, { __index = function(t, k)
                if k == "Changed" then
                    return { connect = function(dummy, func)
                        getter = func
                    end }
                end
            end,
            __tostring = function(t)
                return ""..t.Value
            end})
        end
        if k == "Changed" then
            return { connect = function(dummy, func)
                getter = func
            end }
        else
            return vars[k]
        end
    end,
    __newindex = function(t, k, v)
        local oldValue = t[k] ~= nil and t[k].Value or nil
        vars[k] = setmetatable({ Value = v }, { __index = function(t, k)
            if k == "Changed" then
                return { connect = function(dummy, func)
                    getter = func
                end }
            end
        end,
        __tostring = function(t)
            return ""..t.Value
        end})
        getter(oldValue, v)
    end,
    __metatable = "no",
    })
    return control
end

function lolk(oldValue, newValue)
    print("Old Value: ", oldValue, "New Value: ", newValue)
end

myVars = setVarChangeEvents()
myVars.herp.Changed:connect(lolk)
myVars.herp = 1337
wait(0.5)
myVars.herp = "Moo"
wait(0.5)
myVars.herp = true



---- OUTPUT ----
> Old Value: nil New Value: 1337
Old Value: 1337 New Value: Moo
Old Value: Moo New Value: true
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
15 Dec 2011 07:18 PM
[ Content Deleted ]
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
15 Dec 2011 07:19 PM
[ Content Deleted ]
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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