Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is a changed property for a variable IN a script a thing?

Asked by 9 years ago

I know you can perform a function once a value's value is changed BoolValue.Changed:connect() but what if you had this:

Choice=0

And then there's a button that will do something like this Choice=1 after you click it...

Is it possible to have the script detect whether Choice has changed? I'm looking for a way out of having to make an actual instance for a value every time.

Thank you.

3 answers

Log in to vote
0
Answered by 9 years ago

You can use MessageOut for scripts to communicate with scripts.

local msg = Instance.new("Message", workspace)
Game:GetService("LogService").MessageOut:connect(function(Message, Type)
    msg.Text = "The message was "..Message.." and the type was "..tostring(Type)
end)

print("Hello, World!")

local check = 0
local num = 0

function warn()
    print("The value has changed")
end

game:GetService("LogService").MessageOut:connect(function(message)
    if string.sub(message,1,5) == "check:" and tonumber(string.sub(message,6)) ~= check then
        check = tonumber(string.sub(message,6))
        warn()
    end
end)

while wait(1) do --Just to change the value of num
    num = num+1
    print("check:"..num)
end

Quite complicated but easy, hope this helps!

0
He's not trying to comminucate between two scripts, he's trying to check when a variable has changed. aquathorn321 858 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

You can make an instance to support a specific value:

Assuming that there's aleady a script that changes the value of the NumberValue and V is a reference to the NumberValue:

V.Changed:connect(function(changed)
if changed == 1 then
--run code
end
end)

Alternatively, here's how you could do it in a script without effecting other code in the script using coroutines.

coroutine.resume(coroutine.create(function()
while true do
if changed == 1 then
changed == 0
--run code
end
wait()
end
end))
0
He wants to make it in script. EzraNehemiah_TF2 3552 — 9y
0
I know, but what I can infer through logical thought is that what he really wanted was to accurately tell when a variable changed value. If he doesn't accept my answer, let him thumbs-down it himself. aquathorn321 858 — 9y
0
If you can make 2 scripts communicate, you can make it see if the script's value has changed. I'm finding a lag free way to do so instead of making a loop. My way is making the game less laggy by a ton. EzraNehemiah_TF2 3552 — 9y
0
Besides, at least my answer was relevant. I'll go ahead and adjust it just so I can appease you, though I know you just thumbs-down to spite me. Seriously, grow up. aquathorn321 858 — 9y
View all comments (3 more)
0
He's looking for exactly when the property has changed. He's not looking to see if it's different at a specific time, he's checking to see if it's changed at all. And why are you using messages? aquathorn321 858 — 9y
0
Your method is practically the same as mine since you're still using an instance outside the script, except your method only works once and can't be manipulated without editing the code. That makes my method more efficient and tangible. aquathorn321 858 — 9y
0
Besides, you used a loop at the bottom anyways. aquathorn321 858 — 9y
Log in to vote
-1
Answered by 9 years ago

Here you go, something actually relevant

Choice = 0

BoolValue.Changed:connect(function(change)
    if change == "Value" then --if boolvalue.Value has changed
        Choice = BoolValue.Value --set the choice to the new value
    end
end)

Answer this question