# Live\_Loop does not update

**URL:** <https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160>\
**Category:** Support, Help & Resources\
**Created:** [January 15, 2020, 4:47pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160 "2020-01-15T16:47:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toro](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@Toro](https://in-thread.sonic-pi.net/u/Toro)\
**Post date:** [January 15, 2020, 4:47pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160/1 "2020-01-15T16:47:26Z")

</div>

Hi  
Got myself a Raspberry Pi and discovered Sonic Pi shortly thereafter.

Been having a bit of fun with it, however I can never seem to get Live\_Loops working the way I expect them to, that is to say when I change a variable, it is not reflected in the sound output; I have to hit “run” again Is there a setting somewhere I need to change or is this the expected behavior?

I’ve copied code straight from the tutorial and this does not work either. super simple code until I worked out…

```ruby
    live_loop :foo do
      play 50
      sleep 1
    end

```

Raspbian is up to date, as in Sonic Pi.

Thank you in advance 🙂

---

<div class="post-metadata">

**Author:** ![Toro](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@Toro](https://in-thread.sonic-pi.net/u/Toro)\
**Post date:** [January 15, 2020, 5:16pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160/2 "2020-01-15T17:16:21Z")

</div>

Believe that I have now answered my own question… as far as I can tell, you need to run the code again.

Is this assumption correct - re-read the tutorial, but couldn’t find any clarity from this.

Thanks again

---

<div class="post-metadata">

**Author:** ![perpetual\_monday](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/perpetual_monday/32/955_2.png) [@perpetual\_monday](https://in-thread.sonic-pi.net/u/perpetual_monday)\
**Post date:** [January 15, 2020, 5:21pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160/3 "2020-01-15T17:21:16Z")

</div>

Hi @Toro, you’re correct, you need to execute a run in order for the code to update. This tells the editor “I’m done with this change, apply it now”.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [January 15, 2020, 5:38pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160/4 "2020-01-15T17:38:16Z")

</div>

Hi Toro  
Welcome to in-thread

What you are experiencing is what is expected.  
Basically a live\_loop repeats the code within itself when run is pressed. In this case a repeating note of 50. If you redefine the loop by altering the 50 to say 72, it registers this when you press Run again. However, it finishes the current iteration of the loop and then changes to the new definition on the next run. This keeps things going in time.  
You can see it working if you change things via the program.  
Consider this program:

```ruby
set :n,50

live_loop :foo do
  n=get(:n)
  puts n
  play n
  sleep 1
end

sleep 3.5
set :n,72

```

This stores the value 50 for :n in the time state.  
The live loop starts,retrieves the value of :n and prints and plays it.  
after 3.5 beats the value of :n is set to 3.5  
This is picked up byt the live loop which uses the new value on the next iteration, and 72 is printed and played at time 4

here is the printed output:

```ruby
=> Starting run 90

=> Redefining fn :live_loop_foo

{run: 90, time: 0.0}
 ├─ set :n, 50
 └─ set :n, 50
 
{run: 90, time: 0.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
 
{run: 90, time: 1.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
 
{run: 90, time: 2.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
 
{run: 90, time: 3.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
 
{run: 90, time: 3.5}
 ├─ set :n, 72
 └─ set :n, 72
 
{run: 90, time: 4.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}
 
{run: 90, time: 5.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}
 
{run: 90, time: 6.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}

```

Notive the times at which the varies notes are played:  
at 0,1,2 and 3 50 is played and printed  
at 3.5 n is changed to 72  
at 4,5,…72 is printed and played

---

<div class="post-metadata">

**Author:** ![Toro](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@Toro](https://in-thread.sonic-pi.net/u/Toro)\
**Post date:** [January 15, 2020, 6:17pm UTC](https://in-thread.sonic-pi.net/t/live-loop-does-not-update/3160/5 "2020-01-15T18:17:38Z")

</div>

Thanks for your replies, greatly appreciated.

Read the tutorial over and over, but this fact did not appear to be explicitly stated (or maybe it is and I’m struggling to see the woods for the trees).

Also had a look at the keyboard shortcuts which make it work better too 😊
