It's probably the variable scope.
If you define a variable inside a function, it is local to that function. Outside of the function it's not visible.