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.
Nesting matters: a global is visible everywhere; a program-local variable only inside that program; an FB-internal variable only inside that block. Inner scopes see outward, never the reverse.
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, not a copy β perfect for 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)?