Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Trouble displaying the score in the gameover
Started by dayviex Jul 16 2019 06:38 PM

3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dayviex

[GLOBAL: userInfoPane.html]
dayviex
  • Observer

  • 2 posts
  • Corona SDK

Hey guys so I've been using this tutorial for my score.

https://docs.coronalabs.com/tutorial/games/keepScores/index.html

 

All works well in the actual game, when I use score.add( value ) it adds and when I use score.set( value ) that works as well.

The problem I'm having is the fact that when I use this in the gameover.lua,


	local scoreText = score.init(
	{
	    fontSize = 40,
	    x = 130,
	    y = 130,
	    maxDigits = 7,
	    leadingZeros = false
	})

to display the score as I used it in my game.lua, the score changes during the game, but it will turn to 0 in the gameover.lua and it will not fade in with rest of the scene despite being under show scene.

 

 

And if I try to use this to display the score,

local score = display.newText( sceneGroup, "SCORE: " ..score )

I'll receive the error attempt to concatenate upvalue 'score' (a table value).



[TOPIC: post.html]
#2

prjoh

[GLOBAL: userInfoPane.html]
prjoh
  • Observer

  • 2 posts
  • Corona SDK

Hey.

 

Could you describe what you are doing in gameover.lua? How is it related to your game.lua?

 

I didn't read the tutorial in detail, but it seems to me, that this is a module for displaying and saving a variable in your current scene. If you want to pass this variable to another scene, you would have to use composer.setVariable('finalScore', score.get()) in one scene, and composer.getVariable('finalScore') in another scene.

 

Greetings,

prjoh

 



[TOPIC: post.html]
#3

dayviex

[GLOBAL: userInfoPane.html]
dayviex
  • Observer

  • 2 posts
  • Corona SDK

Hey.

 

Could you describe what you are doing in gameover.lua? How is it related to your game.lua?

 

I didn't read the tutorial in detail, but it seems to me, that this is a module for displaying and saving a variable in your current scene. If you want to pass this variable to another scene, you would have to use composer.setVariable('finalScore', score.get()) in one scene, and composer.getVariable('finalScore') in another scene.

 

Greetings,

prjoh

Essentially I'm just trying to display the score that the player got during the game in the gameover.lua but the problem is i can't display the text without an error.

local score = display.newText( sceneGroup, "SCORE: " ..score )


[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 822 posts
  • Corona SDK

If you've followed that tutorial to a letter, then you shouldn't be touching score variable like that. It is just a module, not the actual display object. You create the score display object with scoreText and that is what you should be manipulating.

 

Without seeing any more of your code, I'd guess that you are seeing that error due to scope, i.e. you create the display object in game scene, but then you try to access it in gameover scene. Simply put, scoreText does not exist in gameover scene. You could pass a reference of it to the gameover scene via composer's parameters table or recreate the score display object in the gameover scene.

 




[topic_controls]
[/topic_controls]