Roryo
|
  |
| Joined: 05 Jun 2008 |
| Total Posts: 113 |
|
|
| 17 Aug 2013 12:56 PM |
| I'm writing a script for a display that reads out the value of a local variable, but I can't get the script to continuously check the variable using if statements, even in a while loop. I'd be very grateful if someone could help me here, because I have no idea. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 17 Aug 2013 12:59 PM |
Yes you can.
x = 5 while (wait()) do assert((x == 5), 'x is no longer 5.') end |
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 17 Aug 2013 01:01 PM |
Try defining the variable in the while loop. For example;
while wait(1) do local value = Workspace.IntValue local msg = Instance.new("Hint",Workspace) msg.Text = "The IntValue equals"..value.Value.."" wait(2) msg:Remove() end
This way, it will redefine value each time |
|
|
| Report Abuse |
|
|
Roryo
|
  |
| Joined: 05 Jun 2008 |
| Total Posts: 113 |
|
|
| 17 Aug 2013 01:13 PM |
| Neither of these worked for me. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2013 01:15 PM |
Is your problem that you need to run things after your while loop? If so, just say so. If not, here's what I'd do:
-- Let's just say that the variable you need is "var" local var2 = var -- This is what we will use to determine if it's changed or not... never change var2 while (wait()) do if (var ~= var2) then print("Var changed") -- You can do something here end end
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Roryo
|
  |
| Joined: 05 Jun 2008 |
| Total Posts: 113 |
|
|
| 17 Aug 2013 01:20 PM |
| I'm actually looking to check a local variable which points to the value of a NumberValue in the workspace, and respond to what its value is with if statements which are inside the loop. However, it only updates the first time, and when the value changes, the script doesn't do anything. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2013 01:22 PM |
Ahhh, okay! Here's what you'd do:
value.Changed:connect(function(thing) -- value being your NumberValue object in Workspace. if (thing == "Value") then -- The value changed, you can do something here end end)
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 17 Aug 2013 01:38 PM |
| ^Make sure to define value |
|
|
| Report Abuse |
|
|