Dear Corona community,
following the Tutorial: Goodbye Globals:
https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
I have a “globalSpace.lua” with the following content:
--my global space local globalSpace = {} return globalSpace
In one of my scenes I require this file using
local globals = require("globalSpace")
outside the scene-functions and add a displayObject to it within my create-function by
local finalImage = display.captureBounds( imageBounds, false ) globals.img1 = finalImage
or
local finalImage = display.captureBounds( imageBounds, false ) globals.img2 = finalImage
, depending on a parameter passed.
If I go to another scene, I have access to these globals.img1 and globals.img2 no problem, I even can update them easily using the code above.
The problem starts here: I can insert globals.img1 into my sceneGroup every time I go to the scene as long as I stick to one parameter. In other words, as long as I set
globals.img1 = finalImage
it works fine, but as soon as I send another parameter and use
globals.img2 = finalImage
and try to insert globals.img2 into my sceneGroup, I get the following error:
bad argument #-2 to 'insert' (Proxy expected, got nil)
If, vice versa, I start with the other parameter and beging with globals.img2, it works fine until I change parameter and go back to globals.img1.
I hope anyone can understand the problem. I just dont get why it says “got nil” even though I can easily access both images. Weird…
Thanks for any help or comments