For Each Loops in Record/Classes

Hey everyone,

Surprisingly enough, I’ve been postponing switching to gamma for many years—but I’ve finally made the move. So, my question might seem like a total newbie one, and I apologize for that in advance.

I’m a bit confused about the Record/Class concept—not in how they handle data (which is clear), but rather in how Operations work inside those patches.

I’m trying to initialize my Record in the Create operation with some default values. My Record type includes a spread of another data type, the size of which should be initially set (based on an input in this particular case). My first thought was to use a ForEach loop to create the spread:

However, for some reason, I can’t assign the whole loop’s data flow to the Create operation (the pad was added as a weird(?) workaround). At first glance, this patch seems to work as expected—it populates the spread with the correct initial values. Assigning everything inside the ForEach region to Update produces the same result.

Still, in both cases, I’m not 100% sure whether the subsequent operations are actually executed during the Create phase.

Is this the correct way to initialize or create values, or have I completely misunderstood the Record/Class concept in gamma?

Thank you for your advice!

I think it is easier to answer in terms of c#

So:

// Your Record pseudo definition
public record MyRecord {
   
    // that's a constructor (Create) 
    MyRecord(Spread<SomeData> programData){
         // now we need to assign 'programData' to something
         _programData = programData;
    }
    // that's the pad:
    private Spread<SomeData> _programData;
    
    // that's operation to get data from MyRecord instance
    public Spread<SomeData> GetSomeData() => _programData;
}

The concept is kinda easy, you create data type e.g. record, you want to store some data in that record, you use pad to store the data, you use Inputs/Outputs + Assign to access or modify data from outside…

So, that means, that I should pass the spread from outside (e.g. Process node) to correctly set it?

In that case things mentioned in this video became even more obscure:

I’m not sure what the problem is, but let’s try from beginning:

When you create record like that, notice the output is MyRecord
Also notice the Filled circle - filled circle means we create new record every frame, to avoid this, we have to assign it to operation:

notice now the circle isn’t filled, we created record and assigned it to a pad on create, we read that pad in update, from iobox.

Now let’s modify record a bit, you say you have spread of something, you want a spread of something else from it:


record_basics.vl (14.0 KB)

3 Likes

Now we want to make it so, we can change it at runtime:

record_basics_cached.vl (14.5 KB)

2 Likes

Now I got it! Thank you very much for a detailed clarification!

1 Like