Custom array reader

I have a problem:

// typdef
typedef struct  {      uchar Hash[20] <format=hex>;  } FSHAHash;
// template
FSHAHash ShaderMapHashes = [ReadInt()] = ReadFSHAHashes();

// somewhere inside the reader func
FSHAHash[] ReadFSHAHashes()
{
    //...
    for(i = 0; i < arrayNum; i++)
    {
        local FSHAHash hash;        
        local uchar temp[20];
        ReadBytes(temp, FTell(), 20)
        hash.data = temp;
        FSkip(8);
    }
}

I need to create new struct and temp array each time because these are unique objects. So I can’t move them outside of FOR scope. But I also can’t use them inside FOR scope because it complains it is defined.
What do.

Typically in Templates you don’t define functions that create structs, you just define the structs directly. The logic for reading the data is usually directly inside the struct. For example, to create an array of FSHAHash structures you could use:

typedef struct  {      uchar Hash[20] <format=hex>;  } FSHAHash;

typedef struct {
    int arrayNum; // or however the array size is calculated
    
    local int i;
    for(i = 0; i < arrayNum; i++)
    {
        FSHAHash hash;
        FSkip( 8 );
    }
    
} FSHAHashArray;

FSHAHashArray array;

Will this work for you?

Graeme
SweetScape Software

No, because I simplified example, the actual logic is much more complex and if I’d try ti put it inside typedef struct it would just make it an unreadable, ugly and unmanageable mess. The logic in template would need to be updated often in most subtle and specific ways and readability is key