# \[Solved\] Help LUA: print in real time the value of selected Track insi

**URL:** <https://forum.renoise.com/t/solved-help-lua-print-in-real-time-the-value-of-selected-track-insi/46442>\
**Category:** Renoise Tool Development\
**Created:** [July 22, 2016, 12:18pm UTC](https://forum.renoise.com/t/solved-help-lua-print-in-real-time-the-value-of-selected-track-insi/46442 "2016-07-22T12:18:36Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![joule](https://forum.renoise.com/user_avatar/forum.renoise.com/joule/32/707_2.png) [@joule](https://forum.renoise.com/u/joule)\
**Post date:** [July 25, 2016, 4:44pm UTC](https://forum.renoise.com/t/solved-help-lua-print-in-real-time-the-value-of-selected-track-insi/46442/15 "2016-07-25T16:44:51Z")

</div>

From the top of my head, some of what I mentioned is used in [https://forum.renoise.com/t/tool-3-1-capture-track-from-instrument/34036](https://forum.renoise.com/t/tool-3-1-capture-track-from-instrument/34036)

The app\_new\_document\_observable should simply be put in the outermost scope of the script (like I do in this script - not within a function). Let it trigger a function that will initialize all other notifiers.

This is what will happen:

1. User is closing a song in Renoise
2. This always make all renoise.song() notifiers destruct automatically (AFAIK)
3. User loads new song
4. app\_new\_document\_observable is banging, if you have set it up. Simply speaking it’s running the function you have told it to run. Here we have the chance to “reinitialize” the script when a new song is loaded. This is especially needed if your script uses various notifiers in renoise.song().

If you just let the notifiers be, and don’t “reinitialize” them on song change, things will go bananas. I don’t 100% know the technical details, but I am guessing the notifiers will believe that you are still in the old song and things will quickly start generating errors.

Common practice example for adding a notifier:

```auto
if not renoise.song().selected_instrument_index_observable:has_notifier(a_function_name) then
 renoise.song().selected_instrument_index_observable:add_notifier(a_function_name)
end

```

For removing a notifier:

```auto
if renoise.song().selected_instrument_index_observable:has_notifier(a_function_name) then
 renoise.song().selected_instrument_index_observable:remove_notifier(a_function_name)
end

```

Good thing to put at the end of your script 🙂

```auto
renoise.tool().app_new_document_observable:add_notifier(my_initialization_function_on_song_load)

```

> – Invoked each time a new document (song) was created or loaded.  
> renoise.tool().app\_new\_document\_observable:add\_notifier(function() handle\_app\_new\_document\_notification() end)

Hmm. I wonder if that syntax works. Perhaps it does, but it seems redundant. This is how I would write it:

```auto
renoise.tool().app_new_document_observable:add_notifier(handle_app_new_document_notification)

```

---

_[View the full topic](https://forum.renoise.com/t/solved-help-lua-print-in-real-time-the-value-of-selected-track-insi/46442)._
