I am rewriting my code to implement scenemanager. Being just a hobby programmer, I ran in various expected scope problems. But this one really surprised me.
So my main.lua for now is
| application:setBackgroundColor(0x000000)
 
print("Starting...")
 
--define scenes
sceneManager = SceneManager.new({
    --start scene
    ["start"] = start,    
    ["level1"] = level1,   
    ["gameover"] = GameOver
})
 
 
--add manager to stage
stage:addChild(sceneManager)
 
sceneManager:changeScene("level1") | 
My level1.lua starts with this line:
| level1 = gideros.class(Sprite) | 
Somewhere, I have a
| function level1:moveRedMotherShip(dt) | 
And its moveBlueMotherShip(dt) equivalent.
Finally, here is my onEnterFrame function:
| function level1:onEnterFrame(e) 
 
	local dt = e.deltaTime
 
	local numSprite = stage:getNumChildren()
 
	level1:moveRedMotherShip(dt) -- move red ship
	level1:moveBlueMotherShip(dt)
end | 
Everything works here. What does not work is when I change
| local numSprite = stage:getNumChildren() | 
into
| local numSprite = level1:getNumChildren() | 
It spits "index '__userdata' cannot be found"
Yet,
| level1:moveBlueMotherShip(dt) | 
works. 
Why the latter works and not level1:getNumSprite() ? I thought that "level1" being a sprite could call any sprite method. Please enlight me. There is something here I need to understand.                
Comments
Likes: hgy29
@Dafb
You can read about "self" here: http://www.lua.org/pil/16.html
Also "level1:getNumSprite()" can be used as "level1.getNumSprite(self)"
Likes: MoKaLux
I believe the main issue was I forgot to add
require ("scenemanager")
in main.lua.
Silly stuff! I also use now as advised
Core.class instead of gideros.class
Everything works now
Thank you again.
Likes: MoKaLux