I think the big thing to understand is there are 2 type of variables :
1 - Storyboard Variables - Created in Designer and can be used to manipulate controls on screen http://cranksoftware.com/cranksoftware/docs/v1.3/ch01s02.html#d0e226
2 - Lua Variables - Created in Lua and good for tracking state, but only by using gre.set_data() can it change anything displayed on the screen.
If you created errorCode variable in your Lua init function and didn't define it as "local" it would automatically be consider a global in Lua's context, so when you did a print(errorCode) in another function the value would be correct.
If you use Storyboard IO to set a variable from another application you will be setting a Storyboard Variable. So if you want access to it Lua you'll need to do a gre.get_data() to get the value. There is no way from Storyboard IO to directly manipulate a Lua Variable. The best way to send data to a Lua function, that isn't needed for manipulating something displayed on the screen, is to create a custom event and send it as event data to the Lua function.
Hope this helps