Storyboard is a rebel and do not want to be required

Hi,

I need to put that piece of code into a separate lua file because I use it in every scene of the storyboard api :

  
local function navControler(event)  
 local direction = "slideLeft"  
 local scene = event.target.name  
  
 if (event.phase == "ended") then  
 if scene == "back" then  
 direction = "slideRight"  
 scene = previousScene  
 end  
 if scene ~= "now" then  
 storyboard.gotoScene(scene, direction,500)  
 end   
 end  
  
 return true  
end  
ui\_back:addEventListener ("touch", navControler)  
ui\_now:addEventListener ("touch", navControler)  
ui\_rock:addEventListener ("touch", navControler)  
ui\_yellow:addEventListener ("touch", navControler)  

Of course, it doesn’t work :

1/ Storyboard “object” (not sure it is one) is broken

2/ Evenlisterner are crying :wink:

[import]uid: 5578 topic_id: 20888 reply_id: 320888[/import]

Are you doing

  
local storyboard = require("storyboard")  

In that file? [import]uid: 84637 topic_id: 20888 reply_id: 82327[/import]

yes but the listener are going mad.
Corona says “attempt to index global ‘screenGroup’ (a nil value)”

I do not understand clearly what happens : if I require again the storyboard API I will create another instance of the storyboard ?

What I want is to manage a graphical navigation bar through differents scene, that’s all. [import]uid: 5578 topic_id: 20888 reply_id: 82339[/import]

I don’t see any reference to screengroup.

can you post up more code?

and no you wont be creating another instance
[import]uid: 84637 topic_id: 20888 reply_id: 82349[/import]

Here’s more code :

  
function scene:createScene( event )  
 --------------------   
 --- HEADER DEF -----  
 --------------------  
  
 local blackHeader = require("blackHeader")  
 -- this blackHeader file contains image.display / image.x / ... created through createBlackHeader below  
  
 local screenGroup = self.view  
 local ui\_back, ui\_logo, ui\_share = blackHeader.createBlackHeader()  
  
  
 screenGroup:insert( ui\_back )  
 screenGroup:insert( ui\_logo )  
 screenGroup:insert( ui\_share )  
  
----------------------  
--- Footer Def --  
----------------------  
 local navGene = require("navGene")  
local ui\_now, ui\_rock, ui\_yellow = navGene.createNavGene("rock")  
  
screenGroup:insert( ui\_now )  
screenGroup:insert( ui\_rock )  
screenGroup:insert( ui\_yellow )  
----------------------  
--- FIN Footer Def --  
----------------------  
  
local ui\_qa, ui\_trends, ui\_season, ui\_agenda = navGene.createNavNow()  
  
screenGroup:insert( ui\_qa )  
screenGroup:insert( ui\_trends )  
screenGroup:insert( ui\_season )  
screenGroup:insert( ui\_agenda )  
  

Now all these stuff should be outside this lua file to be shared through scene

local function navControler(event)  
 local direction = "slideLeft"  
 local scene = event.target.name  
  
 if (event.phase == "ended") then  
 if scene == "back" then  
 direction = "slideRight"  
 scene = previousScene  
 end  
  
 if (scene == "now") then  
 direction = "slideRight"   
 end  
 if scene ~= "rock" then  
 storyboard.gotoScene(scene, direction,500)  
 end   
 end   
 return true  
end  
ui\_back:addEventListener ("touch", navControler)  
ui\_now:addEventListener ("touch", navControler)  
ui\_rock:addEventListener ("touch", navControler)  
ui\_yellow:addEventListener ("touch", navControler)  
  
end  
  

I am not sure to be clear, sorry.
[import]uid: 5578 topic_id: 20888 reply_id: 82354[/import]

Sorry for the late reply.

Screengroup is nil because its local to your other files

Im on my phone right now but something like this will work

function navController(event, group)  
  
--insert objects  
group:insert(whatever)  
end  
  
-- And calling it  
navController(screenGroup)  
  

as i said i wrote this from my code so it might not be 100% plug and play code but that is the right idea. By doing that your passing the group via your function parameters, so you will no longer get group=nil errors.

There might be a more elegant way of doing this, il look again when im back home. (about an hour or so from now) [import]uid: 84637 topic_id: 20888 reply_id: 82698[/import]