Author Topic: Scope of variables  (Read 578 times)

I'm interested in using a pixel processor to calculate the bounding box of a shape.  Then as a second step I want to use that info to position and scale a pattern.  However, I'm not sure how to properly set variables in a pixel processor so it's accessible elsewhere in the graph.

Do the vars need to be param of the graph to stay in scope? 





More questions:
1.  The doc states "When you create an input parameter, a variable is created and associated with it. You can then reuse this variable in any function of you graph"

I'm get the impression those can only be read by the graph and that I can't set input parameters using a set node.  Is that correct?

2.  What's the life of a variable?  Or how do I reset a variable at the beginning of a process?

For example, I would like to have a variable called "startProcessing".  When True, I do the processing.  However, I need to reset it at some point.  If I was coding I'd do something like:

def ProcessGraph():
    startProcessing= False

    #pixel process
    for pixel in image:
        if sample(pos) == targetColor:
            startProcessing= True

        if startProcessing:
            #DoSomeStuff


In the above example I'm resetting startProcessing before sampling the image.  Not sure how to do this in designer.

I'm starting to get the impression that while subgraphs can gain access to parent graph params, there's really no way to modify the input params.  I.e. in coding terms, it feels like inputs are treated like pass by value and not reference.  Access to higher level scope vars are good for reading, but not writing.

Sound right?

It doesn't look like pixel processors could do what I want anyway, since the pixels are evaluated in parallel.  As far as passing variables through the graph, the solution is to use the value processor in combination of input value nodes and the optional value data blocks you can tack onto existing nodes.