# How to get a ring index

**URL:** <https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136>\
**Category:** Support, Help & Resources\
**Created:** [March 18, 2019, 4:47pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136 "2019-03-18T16:47:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![retroriff](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/retroriff/32/800_2.png) [@retroriff](https://in-thread.sonic-pi.net/u/retroriff)\
**Post date:** [March 18, 2019, 4:47pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/1 "2019-03-18T16:47:44Z")

</div>

Hello,

I have a ring array that is controlled by a rotary encoder, so it loop back round using “tick”:

```
notes = (ring :E4, :F4, :B4)
notes.tick
notes.tick
notes.tick
notes.tick

```

How can I get the current position of the current ring, so I can use it in a different ring? In this example the tick position is 0 (corresponding to E4). Is there any “get ring index” function?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![retroriff](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/retroriff/32/800_2.png) [@retroriff](https://in-thread.sonic-pi.net/u/retroriff)\
**Post date:** [March 18, 2019, 9:04pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/2 "2019-03-18T21:04:03Z")

</div>

> [@retroriff](#):
>
> (ring :E4, :F4, :B4)

Sorry, I have found the solution. It’s so simple as:

```
idx = tick

```

> <https://github.com/sonic-pi-net/sonic-pi/blob/dev/etc/doc/tutorial/09.4-Ticking.md>

Thank you

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 19, 2019, 9:58am UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/3 "2019-03-19T09:58:19Z")

</div>

For clarity, it’s important to note that `.tick` does _not_ increment an index for a given ring, it increments an index for the current `live_loop`. This is an important but subtle distinction 🙂

To look at the current value of a `tick` just call `look` or to look up the current tick value in a ring without incrementing the tick call `.look`.

---

<div class="post-metadata">

**Author:** ![retroriff](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/retroriff/32/800_2.png) [@retroriff](https://in-thread.sonic-pi.net/u/retroriff)\
**Post date:** [March 19, 2019, 10:19am UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/4 "2019-03-19T10:19:43Z")

</div>

Thanks for the clarification. Can I get a different look value for each ring?

```
notes = (ring :E4, :F4, :B4)
notes2 = (ring :C1, :B1, :D1)

define :loop_name do
    notes.tick
    sleep 1
end

define :loop_name2 do
    notes2.tick
    sleep 1
end

loop_name

loop_name2
loop_name2

idx = look

puts idx
```

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 19, 2019, 11:46am UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/5 "2019-03-19T11:46:40Z")

</div>

Ticks are thread local, not scope or method local. So if both `loop_name` and `loop_name2` are called within the same thread, the _same_ tick will be incremented twice. Ticks belong to threads/live\_loops.

If you wish to have more than two ticks running in parallel in the same live loop, then you need to give them different names. This is as simple as putting the name in `(` `)` after you write `tick`:

```ruby
# this will tick both notes 
# and notes2 independently:
notes.tick(:foo)
notes2.tick(:bar)

```

Further info can be found in the _Naming Ticks_ section of the tutorial: [https://sonic-pi.net/tutorial.html#section-9-4](https://sonic-pi.net/tutorial.html#section-9-4)

---

<div class="post-metadata">

**Author:** ![retroriff](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/retroriff/32/800_2.png) [@retroriff](https://in-thread.sonic-pi.net/u/retroriff)\
**Post date:** [March 19, 2019, 1:25pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/6 "2019-03-19T13:25:14Z")

</div>

Ok, I undestand. In this case, how would save a specific look index?

```
idx = look(:foo)
```

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 19, 2019, 2:40pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/7 "2019-03-19T14:40:44Z")

</div>

> [@retroriff](#):
>
> idx = look(:foo)

This code would store the current tick value for the `:foo` tick to a variable called idx 🙂

---

<div class="post-metadata">

**Author:** ![retroriff](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/retroriff/32/800_2.png) [@retroriff](https://in-thread.sonic-pi.net/u/retroriff)\
**Post date:** [March 19, 2019, 3:44pm UTC](https://in-thread.sonic-pi.net/t/how-to-get-a-ring-index/2136/8 "2019-03-19T15:44:11Z")

</div>

Excellent. Thank you!
