Two questions for every variable: who can see it, and how long does it live. Get scope wrong and you'll fight ghost values for days. Click a variable to see exactly where it's reachable.
Scopes nest inside each other. A global is visible everywhere, a program-local variable only inside that program, and an FB-internal variable only inside that block. Inner scopes see out to the globals, never the reverse, and an FB cannot see the locals of the program that calls it.
VAR_INPUT target : REAL; END_VAR // in, by value VAR_OUTPUT done : BOOL; END_VAR // out VAR_IN_OUT buffer : ARRAY[..]; END_VAR // by reference VAR count : UINT; END_VAR // internal, kept VAR RETAIN total : UDINT; END_VAR // survives power-off
βοΈ IN_OUT is by reference. The FB works on the caller's actual variable rather than a copy, which suits big arrays you don't want to duplicate every scan.
π Retain survives power-off. Plain internals reset to their initial value on power-up; mark a variable RETAIN and it keeps its last value across a power cycle.
Can PROGRAM Line1 directly read speed (an internal variable of FB_Conveyor)?