initialize textfield's text

Hi Guys,

I am fiddeling around with API v4.

On startup of my scripts gui, I’d like to display a textfield with the content of renoise.song().selected_sample.name .

If I start the script with an empty instrument, where no sample exists, the variable renoise.song().selected_sample is nil of course, so the script fails.

Does anyone have a good idea how I could catch that exception?

I’d prefer to run a kind of initializer beforehand, but I did not come up with a nice solution.

Kind regards, Chris

EDIT:
Mmm, what about two textfields inside an if clause? One for startup, one for later?

EDIT2:
Well, I found a solution using global variables,… I am new to lua, well, well <_<

  
If not renoise.song().selected_sample == nil then  
 blahbla...  
end