Problem showing new field value

Hello all,
 
I’m very new to Corona / Lua, so forgive me! I have a question. I wanted to make a settings page for a game, where you can set the number of lives you have. I’ve created the page and wanted to use the stepper widget. The problem is, I don’t know how to show the new number of lives you have when you click the stepper. I have a global variable gameLives that has been set at the beginning of the main.lua. I have a seperate function for the settings page:
 
 

function settingsGame()
    local widget = require(“widget”)   
    local currentNumber = gameLives
    local function onPress(event)
        local phase = event.phase
        if “increment” == phase then
            currentNumber = currentNumber + 1
        elseif “decrement” == phase then
            currentNumber = currentNumber - 1
        end
    end
   local newStepper = widget.newStepper
        {
            left = 150,
            top = 200,
            initialValue = currentNumber,
            minimumValue = 1,
            maximumValue = 10,
            onPress = onPress,
        }
   local gameLivesText = display.newText(currentNumber,_W/2-200,270,400,600,native.systemFont,15)
 
I know I’m doing it wrong, but I don’t know how. If I print the variable currentNumber I see that it is updated when I click on the stepper. I just don’t know how to show the updated values on the page…
 
Many thanks in advance!
 
Marcel van Langen

You can change text as simply as

[lua]gameLivesText.text = “sometext”[/lua]

so in your onPress function you can do 

[lua]gameLivesText.text = currentNumber[/lua]

You might run into scoping issues. Put 

[lua]local gameLivesText[/lua] 

at the top of your file. Then skip the ‘local’ in front of newText.

Thanks JonJonsson! I already thought it would be something simple, I just didn’t know what it was…

You can change text as simply as

[lua]gameLivesText.text = “sometext”[/lua]

so in your onPress function you can do 

[lua]gameLivesText.text = currentNumber[/lua]

You might run into scoping issues. Put 

[lua]local gameLivesText[/lua] 

at the top of your file. Then skip the ‘local’ in front of newText.

Thanks JonJonsson! I already thought it would be something simple, I just didn’t know what it was…