zub74
|
  |
| Joined: 13 Sep 2008 |
| Total Posts: 489 |
|
|
| 05 Jun 2014 04:08 PM |
So 2 values, rate and cash. Rate is 1, cash starts at 0
rate=workspace.Rate.Value
cash=workspace.Cash.Value
while true do wait(1) print(cash) if rate>0 then wait(1) cash=cash+rate end end
I have another script that waits 3 seconds then changes the rate to another number. The first script doesn't recognize the change/ continues as if the rate was still 1. Why? |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2014 04:10 PM |
| Because you're not changing the values of the variables.They don't change dynamically like that. |
|
|
| Report Abuse |
|
|
zub74
|
  |
| Joined: 13 Sep 2008 |
| Total Posts: 489 |
|
|
| 05 Jun 2014 04:11 PM |
| How would I detect a change, then? |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2014 04:13 PM |
| Add the variables inside the loop.This way the value will get changed everytimes that loop is executed. |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 05 Jun 2014 04:13 PM |
| Put the variable declarations in the while loop. |
|
|
| Report Abuse |
|
|
zub74
|
  |
| Joined: 13 Sep 2008 |
| Total Posts: 489 |
|
|
| 05 Jun 2014 04:19 PM |
I can't get it to work. I've tried like 5 different configurations or so. Could you write it out? |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 05 Jun 2014 04:21 PM |
while wait(1) do rate=workspace.Rate.Value cash=workspace.Cash.Value print(cash) if rate>0 then wait(1) cash=cash+rate end end |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 05 Jun 2014 04:24 PM |
while wait(1) do rate=workspace.Rate
cash=workspace.Cash print(cash.Value) if rate.Value>0 then wait(1) cash.Value=cash.Value+rate.Value end end
|
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 05 Jun 2014 04:27 PM |
| Whoops. Vlek's got it right. |
|
|
| Report Abuse |
|
|
zub74
|
  |
| Joined: 13 Sep 2008 |
| Total Posts: 489 |
|
|
| 05 Jun 2014 04:28 PM |
Both of your scripts didn't work, for some reason. Fixed it, though. The print needs to be in the if then statement. I also changed it to while true do. while true do rate=workspace.Rate.Value cash=workspace.Cash.Value if rate>0 then wait(1) cash=cash+rate print(cash) end end
|
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 05 Jun 2014 04:45 PM |
| I wouldn't advise that - every time the rate is 0, the while loop freezes your game until it isn't 0. |
|
|
| Report Abuse |
|
|
zub74
|
  |
| Joined: 13 Sep 2008 |
| Total Posts: 489 |
|
|
| 05 Jun 2014 04:47 PM |
| What if I just put else end? |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 05 Jun 2014 04:50 PM |
| You have to yield a loop unless you want everything to run all at once, which usually freezes your game. While wait() do is a good way to avoid anything wrong happening, it's clean, and compact. Else end doesn't do anything. |
|
|
| Report Abuse |
|
|