Normal functions cannot see the variables in the workspace of the caller -- not unless the function specifically asks to look there (which, in most cases, is Not A Good Idea.) You need to pass the values into the function.
There is an alternative: you can define a nested function, and that can see variables in the workspace of the caller that were initialized before the definition of the nested function. For example,
result = visible + invisible;
In this case, inner can see visible because it was assigned to in outer before the function inner was defined, but inner cannot see invisible which was assigned to after inner was defined -- and this rule holds even though invisible is assigned to in outer before inner is called