Passing variables/properties - how hard can it be???

I realize this question has been asked multiple times, but I seem to be incapable of understanding the answers I read, so if anyone has an “Idiots Guide” type explanation of how to pass a property/variable from screen to screen/ module to module, I would really appreciate it.

Ideally, I’d like to be able to pass said variable through the changeScene function of Director Class (or I can switch to Storyboard if that would make this any easier). For instance, tap a button and be able to pass some identifying feature like “A”, “B”, or "C on to the next scene so I could load different information depending on what was passed in.

In other languages you’d simply set up a global variable and be done with it. That isn’t working for me, even using _G.someidentifyingpropertyname. Everything comes up nil.

Sorry for the rambling. If you’ve ever tried to drive around Washington DC, you’ll know the state of mind this is putting me in! (i.e., driving around the beltway - “I can SEE the Kennedy Center”, just can’t find a way to GET there."!)

Many thanks for any guidance!!

Chris [import]uid: 97836 topic_id: 21917 reply_id: 321917[/import]

Let me try to summarize this:

  1. Use globals:
--main.lua  
  
fred = 10  
--game.lua  
  
print(fred) -- should print 10.  

Globals are messy and game.luy may need the variable fred in a different context. So we have the super global: _G. Which is a big lua table:

--main.lua  
\_G.fred = 10  
--game.lua  
  
print(\_G.fred) -- should print 10.  

If you’re using storyboard, you do a:

local storyboard = require("storyboard") i  

in each module. “storyboard” is a big lua table that you can add values to:

--main.lua  
  
local storyboard = require("storyboard")  
storyboard.fred = 10  
storyboard.gotoScene("game")  
  
--game.lua  
local storyboard = require("storyboard")  
  
print(storyboard.fred) -- should print 10.  

Director really doesn’t have a feature like storyboard does to be able to add variables to the storyboard table. But the Super globals should work.

Director, at least with 1.4 and later (possibly earlier) does allow you to pass parameters to scenes. I don’t know the exact syntax but its something like:

--main.lua  
  
director.changeScene({fred = 10}, "game")  
  
--then in game.lua  
  
function new(params)  
 local localGroup = display.newGroup()  
 local myVars = {}  
 if type(params) == "table" then  
 myVars = params  
 end  
 print(myVars.fred) -- should print 10  
 return localGroup  
end  

All of those techniques have worked for me.
[import]uid: 19626 topic_id: 21917 reply_id: 87139[/import]

@Rob - Such a Awesome Explanation even for me that did not ask for it. :wink:
I would say I highly appreciate your shared time as above.

PS: Sorry @cpalmer5219.
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 21917 reply_id: 87140[/import]

@robmiracle

Thanks so much for this - it does clear some things up for me and I can see now that my issues run deeper than I previously thought - seems I’m trying to change _G.fred from within addEventListener(), which, as I am reading, possibly will not scope correctly.

Any chance you have any pearls of wisdom about how to accomplish that trick? I thought it would be clever to create all of my buttons, give them a local variable name, and then run

localVariable:addEventListener(“touch”, changeScene)

–changeScene simply calls director:changeScene –

What I really am attempting to do is pass localVariable.fred into changeScene, then make _G.fred = localVariable.fred within changeScene before calling director:changeScene.

Does this make sense?

Thanks so much for your help :slight_smile:

Chris [import]uid: 97836 topic_id: 21917 reply_id: 87170[/import]

This is very nice, Larry. Thank you for sharing. I’ve bookmarked it to look more closely later (after this madness of finishing up my game is over…)

Naomi [import]uid: 67217 topic_id: 21917 reply_id: 87192[/import]

@Larry - Thank you SO much too!

Wonderful Sharing!
Cheers,
Rodrigo.
[import]uid: 89165 topic_id: 21917 reply_id: 87193[/import]

Oh Larry, because of you I will actually sleep tonight! Thank you so much for taking the time to share this. There just are no words to express my gratitude… it really blows my mind how helpful people are in this community - I only hope I will have enough knowledge and experience some day to repay the kindness.

Best,

Chris [import]uid: 97836 topic_id: 21917 reply_id: 87199[/import]

@cpalmer5219

Inside your touch handler you should have a “self” variable which in your case is “localVariable”. So inside the event listener function you should be able to either access:

self.fred

or

event.target.fred [import]uid: 19626 topic_id: 21917 reply_id: 87306[/import]

Hi All,

Thanks, hopefully it will help explain how not to use
global vars, if you can help it… using Director ver. 1.4.
(modifed ver. 1.4 that is…)

I would like to thank Ricardo Rauber Pereira for his
hard work and letting us all use his Director class
…hats off, to you Ricardo! :wink:

Thanks Rob, for giving me the idea…to try all this…

Have fun!
Larry
Willow Road games [import]uid: 107633 topic_id: 21917 reply_id: 87308[/import]

@robmiracle,

Thanks so much - you are absolutely right. Within the touch handler, all I had to do was add one line:

_G.variable = e.target.variable

Since this is a small app and I only need the one global, I can probably get away with the global. If nothing else, this will allow me to continue flushing out my app until I can completely wrap my head around not using globals.

Thanks so much for your assistance!

Best,

Chris [import]uid: 97836 topic_id: 21917 reply_id: 87316[/import]

@sharp1959,

Wow - this is incredible stuff, and thank you. I think it will take a while for me to really wrap my head around it, but it’s obviously a more elegant way of passing around variables. Going to digest it a bit at a time.

If I may ask one more question, however: it works beautifully with Director 1.4 if I do not modify it. When I replace “module(…, package.seeall)” with “local director = {}” and add the line “return director” to the end of the file, I get the following error: (and yes, I did remove the quotes :-))

Runtime error
…x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:40: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’
…x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:40: in function ‘main’
…x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:48: in main chunk
Runtime error: …x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:40: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’
…x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:40: in function ‘main’
…x0hb5k4j_7_1xry7m0000gn/T/TemporaryItems/78/main.lua:48: in main chunk

Again, thank you and yes, KUDOS to Ricardo Rauber!!!

Best,

Chris [import]uid: 97836 topic_id: 21917 reply_id: 87320[/import]

Hi Guys,

The Director forum may be a better place for this, but
I made a quick little director example to use a table
as in Rob’s example above…works great…:slight_smile:

…look no globals…:wink:

main.lua

  
--\*\* main.lua  
--\*\* This is your basic main.lua file keep it simple  
--\*\* the only thing you really need to add is global vars  
--\*\* or table. (and this is how you do it WITH-OUT global vars.)  
display.setStatusBar( display.HiddenStatusBar );  
  
--\*\* I used modified director.lua file: ---- modified ver. 1.4 used ----  
--\*\* from this post ( link is posted in #6 reply)  
--\*\*  
--\*\* http://developer.anscamobile.com/forum/2011/09/07/modified-director-jonathan-beebes-blog-post  
--\*\* Thanks for all that helped with this ver. of director  
--\*\*  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*NOTE\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
--\*\*  
--\*\* all tho' you CAN use the ORIGINAL Director Class ver. 1.4 the  
--\*\* version linked above just gets rid of the "module( ..., package.seeall )"  
--\*\* and replaces it with a table. Lua eventually will do away with  
--\*\* the "module( ..., package.seeall )" in future versions, as posted  
--\*\* on their main lua site. http://www.lua.org  
--\*\*   
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*END OF NOTE\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
director = require("director");  
  
local mainGroup = display.newGroup();  
  
--\*\*  
--\*\* make our table that we can pass all through our director class  
--\*\* and use the contents with-in our modules to change or use as is.  
--\*\*  
local myTable = {};  
myTable.whiteshoe = 164;  
myTable.brownshoe = 18;  
myTable.greenshoe = 1507;  
myTable.redshoe = 1453;  
--\*\* myTable.purpleshoe = true; --\*\*  
--\*\* myTable.gameSave = false; --\*\*\* you can add what-ever you like  
--\*\* myTable.buttonStatus = true; --\*\*\* all our vars to keep track of  
--\*\* myTable.hotgame = 1234569; --\*\*  
myTable.mytext = "Game over!";  
myTable.gmenu = "Game Menu";  
myTable.g1 = "Game Scene 1";  
myTable.g2 = "Game Scene 2";  
myTable.g3 = "Game Scene 3";  
myTable.screenWidth = display.contentWidth; --\*\* our screen width  
myTable.screenHeight = display.contentHeight; --\*\* our screen height  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*END OF OUR TABLE\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
local main = function()  
  
 mainGroup:insert(director.directorView);  
  
 director:changeScene(myTable, "gamemenu", "crossfade");  
  
 return true;  
end   
main();  
return true;  

gamemenu.lua

--\*\* gamemenu.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
 --\*\*  
 --\*\* for testing our table inside main.lua  
 --\*\* prints to simulator output window  
 print("\nInside gamemenu.lua");  
 print("greeshoe: ", myTable.greenshoe);  
 print("whiteshoe: ", myTable.whiteshoe);  
 print("brownshoe: ", myTable.brownshoe);  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
  
 --\*\* example button only  
 local playButton\_menu = display.newRect((myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 400, 220, 50);  
 playButton\_menu.strokeWidth = 3;  
 playButton\_menu:setFillColor(140, 140, 140);  
 playButton\_menu:setStrokeColor(180, 180, 180);  
 playButton\_menu.scene = "gamescene1";  
 localGroup:insert(playButton\_menu);  
  
 --\*\* display our text on to the button  
 local buttonText = display.newText(myTable.gmenu, (myTable.screenWidth / 2) - 80, (myTable.screenHeight / 2) - 400, native.systemFont, 16\*2);  
 buttonText:setTextColor(255, 255, 255);  
 localGroup:insert(buttonText);  
  
 --\*\*  
 --\*\* our move to next scene function  
 --\*\*  
 local function nextSceneSelect(e)  
  
 if(e.phase == "ended") then  
  
 --\*\* clean up our garbage before we move on / director class also cleans it's self  
 local cleanTmr = timer.performWithDelay(1, function() collectgarbage("collect") end);  
 timer.cancel(cleanTmr);  
  
 director:changeScene(myTable, e.target.scene, "crossfade");  
  
 end  
  
 return true;  
 end  
  
  
 --\*\*  
 --\*\* our button event listener  
 --\*\*  
 playButton\_menu:addEventListener("touch", nextSceneSelect);  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

gamescene1.lua

--\*\* gamescene1.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
 --\*\*  
 --\*\* for testing our table inside main.lua  
 --\*\* prints to simulator output window  
 print("\nInside gamescene1.lua");  
 print("greeshoe: ", myTable.greenshoe);  
 print("whiteshoe: ", myTable.whiteshoe);  
 print("brownshoe: ", myTable.brownshoe);  
  
 --\*\*  
 --\*\* add two shoes together (each time we are in this module / scene)  
 --\*\*  
 myTable.brownshoe = (myTable.brownshoe + myTable.greenshoe);  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
  
 --\*\* example button only  
 local playButton\_menu = display.newRect((myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 300, 220, 50);  
 playButton\_menu.strokeWidth = 3;  
 playButton\_menu:setFillColor(140, 140, 140);  
 playButton\_menu:setStrokeColor(180, 180, 180);  
 playButton\_menu.scene = "gamescene2";  
 localGroup:insert(playButton\_menu);  
  
 --\*\* display our text on to the button  
 local buttonText = display.newText(myTable.g1, (myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 300, native.systemFont, 16\*2);  
 buttonText:setTextColor(255, 255, 255);  
 localGroup:insert(buttonText);  
  
  
 --\*\*  
 --\*\* our move to next scene function  
 --\*\*  
 local function nextSceneSelect(e)  
  
 if(e.phase == "ended") then  
  
 --\*\* clean up our garbage before we move on / director class also cleans it's self  
 local cleanTmr = timer.performWithDelay(1, function() collectgarbage("collect") end);  
 timer.cancel(cleanTmr);  
  
 director:changeScene(myTable, e.target.scene, "crossfade");  
  
 end  
  
 return true;  
 end  
  
  
 --\*\*  
 --\*\* our button event listener  
 --\*\*  
 playButton\_menu:addEventListener("touch", nextSceneSelect);  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

gamescene2.lua

--\*\* gamescene2.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
 --\*\*  
 --\*\* for testing our table inside main.lua  
 --\*\* prints to simulator output window  
 print("\nInside gamescene2.lua");  
 print("greeshoe: ", myTable.greenshoe);  
 print("whiteshoe: ", myTable.whiteshoe);  
 print("brownshoe: ", myTable.brownshoe);  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
  
 --\*\* example button only  
 local playButton\_menu = display.newRect((myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 200, 220, 50);  
 playButton\_menu.strokeWidth = 3;  
 playButton\_menu:setFillColor(140, 140, 140);  
 playButton\_menu:setStrokeColor(180, 180, 180);  
 playButton\_menu.scene = "gamescene3";  
 localGroup:insert(playButton\_menu);  
  
 --\*\* display our text on to the button  
 local buttonText = display.newText(myTable.g2, (myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 200, native.systemFont, 16\*2);  
 buttonText:setTextColor(255, 255, 255);  
 localGroup:insert(buttonText);  
  
 --\*\*  
 --\*\* our move to next scene function  
 --\*\*  
 local function nextSceneSelect(e)  
  
 if(e.phase == "ended") then  
  
 --\*\* clean up our garbage before we move on / director class also cleans it's self  
 local cleanTmr = timer.performWithDelay(1, function() collectgarbage("collect") end);  
 timer.cancel(cleanTmr);  
  
 director:changeScene(myTable, e.target.scene, "crossfade");  
  
 end  
  
 return true;  
 end  
  
  
 --\*\*  
 --\*\* our button event listener  
 --\*\*  
 playButton\_menu:addEventListener("touch", nextSceneSelect);  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

gamescene3.lua

--\*\* gamescene3.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
 --\*\*  
 --\*\* for testing our table inside main.lua  
 --\*\* prints to simulator output window  
 print("\nInside gamescene3.lua");  
 print("greeshoe: ", myTable.greenshoe);  
 print("whiteshoe: ", myTable.whiteshoe);  
 print("brownshoe: ", myTable.brownshoe);  
  
 print("Our Text String: ", myTable.mytext);  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
  
 --\*\* example button only  
 local playButton\_menu = display.newRect((myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 100, 220, 50);  
 playButton\_menu.strokeWidth = 3;  
 playButton\_menu:setFillColor(140, 140, 140);  
 playButton\_menu:setStrokeColor(180, 180, 180);  
 playButton\_menu.scene = "gamemenu";  
 localGroup:insert(playButton\_menu);  
  
 --\*\* display our text on to the button  
 local buttonText = display.newText(myTable.g3, (myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 100, native.systemFont, 16\*2);  
 buttonText:setTextColor(255, 255, 255);  
 localGroup:insert(buttonText);  
  
 --\*\* display our game over text  
 local gameovertext = display.newText(myTable.mytext, (myTable.screenWidth / 2) - 80,(myTable.screenHeight / 2), native.systemFont, 16\*2);  
 gameovertext:setTextColor(100, 100, 100);  
 localGroup:insert(gameovertext);  
  
 --\*\*  
 --\*\* our move to next scene function  
 --\*\*  
 local function nextSceneSelect(e)  
  
 if(e.phase == "ended") then  
  
 --\*\* clean up our garbage before we move on / director class also cleans it's self  
 local cleanTmr = timer.performWithDelay(1, function() collectgarbage("collect") end);  
 timer.cancel(cleanTmr);  
  
 director:changeScene(myTable, e.target.scene, "crossfade");  
  
 end  
  
 return true;  
 end  
  
  
 --\*\*  
 --\*\* our button event listener  
 --\*\*  
 playButton\_menu:addEventListener("touch", nextSceneSelect);  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

This all should work fine, as I tested and copied here…
Interesting tho, how it all works great…

Tested with Profiler.lua and memory is…after load
and playing…goes flatline…(stable) :wink:
EDIT: cleaned it up a little and added a button/name
for every scene and more vars to our table to help explain
it all a little better / how it all works…:slight_smile:
Happy coding :wink:

Larry
Willow Road games [import]uid: 107633 topic_id: 21917 reply_id: 87187[/import]

Hi cpalmer5219,
Try this link and look at post #6, and download
the Director class from github…

http://developer.anscamobile.com/forum/2011/09/07/modified-director-jonathan-beebes-blog-post

My bad…there were more edits inside director.lua
I will change my above post inside main.lua to
include the link for the correct ver
That will do it…

PS. Yes you can use the original Director, the modified
Director just gets rid of the “module( …, package.seeall )”
and uses a global table to pass objects…:slight_smile:

Happy coding

Larry
Willow Road games [import]uid: 107633 topic_id: 21917 reply_id: 87325[/import]

Thanks so much Larry. I really appreciate you :slight_smile:

  • Chris [import]uid: 97836 topic_id: 21917 reply_id: 87360[/import]

can i use this method with popUps? i tried to see my variables on a other place, and it didnt do anything:/ [import]uid: 26056 topic_id: 21917 reply_id: 87368[/import]

Hi Blickon,
Yes, you can use this method using popups, ie:

director:openPopUp( myTable, "gamescene4", popClosed );  

You will need to code the popup “gamescene4” or whatever
you name it and also the popClosed function director calls
when it’s finished with the popup or you close it…

something like…
gamescene4.lua

--\*\* gamescene4.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
 print("\n\nInside Our popup window");  
 print("greenshoe: ", myTable.greenshoe);  
  
  
 local popUp = display.newRect(150, 150, 320, 480);  
 popUp.xScale = 0.9  
 popUp.yScale = 0.9  
 popUp.alpha = 0.6  
  
 localGroup:insert(popUp);  
  
 local touched = function ( event )  
 if event.phase == "ended" then  
 director:closePopUp();  
 end  
 end  
  
 popUp:addEventListener("touch" , touched );  
  
  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

for a quick example I just re-coded “gamescene3.lua”
to test it…like this

(rename “gamescene3.lua” first to save it…then)
Just replace the “gamescene3.lua” file above with this one
and all should work fine to help you understand…

Quick and dirty…to test it all together

gamescene3.lua

--\*\* gamescene3.lua  
local M = {};  
  
--\*\* local vars here if you need them  
--\*\* in the module  
  
M.new = function(params)  
 local localGroup = display.newGroup();  
  
 --\*\*  
 --\*\* make a local table to hold our passed params  
 --\*\*  
 local myTable = {};  
  
 if type (params) == "table" then  
 myTable = params;  
 end  
  
  
  
  
 local popClosed = function()  
 --\*\*  
 --\*\* for testing our table inside main.lua  
 --\*\* prints to simulator output window  
 print("\nInside gamescene3.lua");  
 print("greeshoe: ", myTable.greenshoe);  
 print("whiteshoe: ", myTable.whiteshoe);  
 print("brownshoe: ", myTable.brownshoe);  
  
 print("Our Text String: ", myTable.mytext);  
  
 --\*\*  
 --\*\* put more functions / game logic in this area for this scene / module  
 --\*\*  
  
 --\*\* example button only  
 local playButton\_menu = display.newRect((myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 100, 220, 50);  
 playButton\_menu.strokeWidth = 3;  
 playButton\_menu:setFillColor(140, 140, 140);  
 playButton\_menu:setStrokeColor(180, 180, 180);  
 playButton\_menu.scene = "gamemenu";  
 localGroup:insert(playButton\_menu);  
  
 --\*\* display our text on to the button  
 local buttonText = display.newText(myTable.g3, (myTable.screenWidth / 2) - 100, (myTable.screenHeight / 2) - 100, native.systemFont, 16\*2);  
 buttonText:setTextColor(255, 255, 255);  
 localGroup:insert(buttonText);  
  
 --\*\* display our game over text  
 local gameovertext = display.newText(myTable.mytext, (myTable.screenWidth / 2) - 80,(myTable.screenHeight / 2), native.systemFont, 16\*2);  
 gameovertext:setTextColor(100, 100, 100);  
 localGroup:insert(gameovertext);  
  
  
  
 --\*\*  
 --\*\* our move to next scene function  
 --\*\*  
 local function nextSceneSelect(e)  
  
 if(e.phase == "ended") then  
  
 --\*\* clean up our garbage before we move on / director class also cleans it's self  
 local cleanTmr = timer.performWithDelay(1, function() collectgarbage("collect") end);  
 timer.cancel(cleanTmr);  
  
 director:changeScene(myTable, e.target.scene, "crossfade");  
  
 end  
  
 return true;  
 end  
  
  
 --\*\*  
 --\*\* our button event listener  
 --\*\*  
 playButton\_menu:addEventListener("touch", nextSceneSelect);  
  
 return true;  
 end --\*\* end of our popClosed function  
  
  
  
  
  
  
 --\*\* this is called first to see if our value == 164  
 --\*\* call a popup window if our var == a value (just a example)  
 if myTable.whiteshoe == 164 then  
 director:openPopUp( myTable, "gamescene4", popClosed );  
 --\*\* we pass the table, filename of our scene, and then the function we  
 --\*\* want called when our popup is closed.  
 end  
  
  
  
  
  
 --\*\*  
 --\*\* always return our group  
 --\*\*  
 return localGroup;  
  
end  
  
--\*\*  
--\*\* always have to return  
--\*\*  
return M;  

Hope that helps a little bit, I must say this just a
sample…but, hopefully it explains the concept… :slight_smile:
(kind of messy sample…needs to be clean-up)…I like
neat-ness…:slight_smile:
Happy Coding,
Larry
Willow Road games [import]uid: 107633 topic_id: 21917 reply_id: 87483[/import]

Hi sharp1959, thank you very much for the help, and i tried your code, but something is wrong, i cant see the results,can we work on a simple example?without images or other codes, only the essencial to goal :slight_smile:

Very simple example:

  
-- Scene1   
function new ()  
local game = true  
end  
  
-- Scene2  
now how can i see and use te variable game declared on Scene1?  
  

Thanks [import]uid: 26056 topic_id: 21917 reply_id: 87869[/import]

Hi Blickon,

I put a simple version together, using director here:

http://www.filefactory.com/file/c3c6c78/n/SimpleVersion.zip
“local” variables declared in one scene SHOULD not be
used in other files, that’s why they are local, to
THAT scene or module ONLY…hope that makes sense, study
the simple version I linked above, if you want to see
how I use variables and GLOBALS…

Hope that helps :wink:

Happy Learning,
Larry
Willow Road games
[import]uid: 107633 topic_id: 21917 reply_id: 87949[/import]

hmm, it is very nice, but we shouldnt use global variables :confused: [import]uid: 26056 topic_id: 21917 reply_id: 87952[/import]

Hi guys,

Correct, the simple ver, just shows how to use global
var and passing vars, so you don’t have to use
global variables…but yes you shouldn’t use global
variables UNLESS you absolutely have to…:slight_smile:
(it just shows comparison)
Always a exception to the rule, but for the most part
try not to use globals…
Best Regards,

Larry
Willow Road games

[import]uid: 107633 topic_id: 21917 reply_id: 87957[/import]