Grabbing Score From Other Lua Page

hi there, recently im trying to figure out how to show up something from other lua page. Basically in game.lua i have score number and i want to show it up in gameover.lua so the player would know how good his score is after the character dies.

I learned much from this simple youtube video about corona:

http://www.youtube.com/watch?v=WX1Swovbhms

but i simply couldn’t implement it to my game. not sure why…

in my gameover.lua i have this code:

local scoreText = display.newText ("Your Score Is: ", 75, 150, Arial, 20) local scoreNumber = require("game") scoreNumber = score scoreNumber.x = 100 scoreNumber.y = 35

Im sorry if it sounds like a stupid question but can you tell me how do i “pull” the score number from game.lua (which is called “score” there) to be seen in gameover.lua? [import]uid: 114765 topic_id: 24323 reply_id: 324323[/import]

What are you using to change scenes? Storyboard or Director or some home brewed method?
[import]uid: 19626 topic_id: 24323 reply_id: 98248[/import]

hi there,

im using director to change scene.

here’s how i go from game.lua to gameover.lua

 director:openPopUp ("gameover", popClosed)

*and yes, im using a pop up for gameover.lua instead of normal director.changeScene [import]uid: 114765 topic_id: 24323 reply_id: 98250[/import]

With Director 1.4 you can use parameters:

local Options = {}  
Options["highscore"] = tostring(YourHighScore)  
director:openPopUp ("gameover", popClosed)  

in gameover.lua:

module(..., package.seeall)  
  
new = function ( params )  
  
if type( params ) == "table" then  
 if type( params.highscore ) == "string" then  
 HighScore = params.highscore  
 end  
end  

Something like that. I only used stringtype in my projects, but you can probably use other types too, like integer.

[import]uid: 50459 topic_id: 24323 reply_id: 98260[/import]

Actually it would be:

director:openPopUp (Options, "gameover", popClosed)  

And you probably don’t need to convert it to a string before passing it.

The other probably more common approach is to use the _G super globals table.

Yea, I know globals are bad, but its only a performance hit if your accessing the variable a lot.

Simply do:

[lua]_G.score = score[/lua]

in the sending module, and in the gameover module:

local scoreText = display.newText (string.format("Your Score Is: %d", score), 75, 150, Arial, 20)  

[import]uid: 19626 topic_id: 24323 reply_id: 98280[/import]

hi guys i’ve found a solution already. thanks a lot for helping! [import]uid: 114765 topic_id: 24323 reply_id: 98319[/import]