Accessing struct argument inside read functuon

typedef struct(NameEntry &names)
{
    int32 Index <read=Str("%s", this[0] > 0 ? names[this[0]].Name : "None")>;
} StructData <optimize=false>;

names array is invalid/non-existent

It’s important to understand that the ‘read’ functions are called only when the Template Results displays data, meaning the ‘read’ functions are called after the Template has finished executing. In this case the names array is no longer available so you have to save the data you want to display into a local variable like this:

typedef struct(NameEntry names[])
{
    int32 Index;
    local string localName = Index > 0 ? names[Index].Name : "None";
} StructData <optimize=false, read=localName>;

This puts the read function on StructData but it could be placed on Index if you wanted. Cheers!

Graeme
SweetScape Software

Although this is few months old post I think it is important mention few characteristics of the read functions that I discovered the hard way:

  • Graeme already mentioned that read function is executed when the Template finished executing. It is actually after each update of the given variable instance a read function applies to. I deliberately say update because if you try to change the said template variable inside read function you will trigger an endless loop. I can understand why read function is triggered by variable change event.
  • hovering over nodes in data panel will trigger read function for a given node. I’m not sure if this is by design or an implementation oversight and possible optimization candidate. To verify it put Printf statement insdie read function.