Zac Baker
Zac Baker

Reputation: 37

Corona sdk scoring?

I'm trying to make a scoring system that displays an all time score across every scene, when a user completes a scene the score from that scene is added to the all time score.

I get 1 error in the compiler: Attempt to perform "arithmetic" on field "score"

code from main lua: contains no errors but not sure if correct. -- 1 Clue 1 Word

display.setStatusBar (display.HiddenStatusBar)

local storyboard = require ( "storyboard" )
storyboard.gotoScene("menu") 

storyboard.state = {}
storyboard.state.score = 0
storyboard.state.score = display.newText(storyboard.state.score, 250, 20, "ARIAL", 16)

<code>

The error appears in the line: storyboard.state.score = storyboard.state.score + 1

<code>
if(correct == #L1) then
    --alert()
    print ("CORRECT "..#L1)
    line.isVisible = false
    storyboard.gotoScene( "scene2", "slideLeft", 500)
    storyboard.state.score = storyboard.state.score + 1
    storyboard.removeScene( "scene1" )
end


end

end

Upvotes: 0

Views: 838

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23737

Why storyboard.state.score assigned twice?

storyboard.state.score = 0
storyboard.state.score = display.newText(storyboard.state.score, 250, 20, "ARIAL", 16)

UPD :

storyboard.state = {score = 0}
score = display.newText(storyboard.state.score, 250, 20, "ARIAL", 16) 

storyboard.gotoScene( "scene2", "slideLeft", 500) 
storyboard.state.score = storyboard.state.score + 1 
storyboard.removeScene( "scene1" ) 

Upvotes: 1

Related Questions