Writing to the song comments

Writing to the song comments would be nice. I just spend an hour or so starting to implement a tool for per track comments until I realized that I cannot write in the song comments!

Yes you can?

-- Song Comments  
renoise.song().artist, _observable  
 -> [string]  
renoise.song().name, _observable  
 -> [string]  
renoise.song().comments[], _observable  
 -> [array of strings]  

From: Renoise.Song.API.lua

Doesn’t work for me, I can only read. When I write something in there, no changes are visible, the array is still the same.

This works fine:
local songcomments = {“This is my new songcomment”, “and now it is empty”}
renoise.song().comments = songcomments

If a similar construction doesn’t work for you, try to make your songcomment array a global variable in the header of your lua-file before adding contents to it.
Usually this is a variable scope issue in Lua and is a pitfall for many.

Ah, so I cannot just write in the renoise.song().comments[] array directly, I have to copy it into a new array, modify that and then set the renoise.song().comments to the new one?

Yeah, that is strange.

I would have expected

renoise.song().comments[1] = “Hello”
renoise.song().comments[2] = “World”

To work?

No that doesn’t work, similar like the song.pos and song.line thing, these have to be ported to a local created variable first, adjusted and then the whole variable has to be given back to the songpos key. So Fladd’s assumption is correct here.

SongPos is an object.

renoise.song().comments is an “Array”.

There’s a big difference. Example:

local my_array = { }  
my_array[1] = "Hello"  
my_array[2] = "World"  



This is a bug IMHO.

All property tables of basic types (strings, numbers, booleans) in the API are temp copies and not references. This is indeed not very comfortable and not obvious, but I could not find a clever way to deal with this in general in the LUA API backend. So I can’t simply “fix” this - sorry.

OK, thanks for the explanation.

I guess that should be documented. I’ll try to add it later today.