Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Widget label not showing live data.
Started by judewilson2024 Dec 01 2019 08:07 PM

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

judewilson2024

[GLOBAL: userInfoPane.html]
judewilson2024
  • Observer

  • 2 posts
  • Corona SDK

Hello, my widget buttons label is not showing live data from user.json. In facto none of my text labels are showing live data.

 

I am making a pen clicking simulator. I have the widget library included it is just not shown in my code here.

 

I have no scenes just main.lua and other data files and other things.

 

I need help where it says "--This is not updating live": 

btnClick = widget.newButton {
    width = 31,
    height = 52,
    defaultFile = "images/"..user.penLevel.."/penCap.png",
    overFile = "images/"..user.penLevel.."/penCapOver.png",
    font = font,
    fontSize = 14,
    labelColor = {default={0,0,0},over={0,0,0}},
    labelYOffset = -350,
    label = "Pen Clicks: " ..user.penClicks, --This is not updating live
    onEvent = onPenClick,

Here is my code:

-- set up a saved file for our user
user = loadsave.loadTable("user.json")
if(user == nil) then 
	user = {}
	user.clicks = 100
	user.penLevel = 0
	user.penLevelMax = 10
	user.penClicks = 0
	user.playsound = true
	loadsave.saveTable(user, "user.json")
end

--call local function
local function onPenClick(event)
    if(event.phase == "ended") then 
		audio.play(click)
		user.penClicks = user.penClicks + 1
		loadsave.saveTable(user, "user.json")
		user = loadsave.loadTable("user.json")
    end
end

-- Game start
local bg = display.newImageRect("images/bg.png", 800, 1400)
bg.x = display.contentCenterX
bg.y = display.contentCenterY
loadsave.saveTable(user, "user.json")
user = loadsave.loadTable("user.json")

--Pen Level Text
local penLevelText = display.newText( "Pen Level: " .. user.penLevel, 0, 0, font, 14 )
penLevelText:setFillColor( 0, 0, 0 )
penLevelText.anchorX = 0.5
penLevelText.x = display.contentCenterX
penLevelText.y = 40
loadsave.saveTable(user, "user.json")
user = loadsave.loadTable("user.json")

--pen images/levels
local penLevelImage = display.newImageRect("images/0/pen.png", 55, 365)
penLevelImage.x = display.contentCenterX
penLevelImage.y = display.contentCenterY

btnClick = widget.newButton {
	width = 31,
	height = 52,
	defaultFile = "images/"..user.penLevel.."/penCap.png",
	overFile = "images/"..user.penLevel.."/penCapOver.png",
	font = font,
	fontSize = 14,
	labelColor = {default={0,0,0},over={0,0,0}},
	labelYOffset = -350,
	label = "Pen Clicks: " ..user.penClicks,
	onEvent = onPenClick,
}
btnClick.x = display.contentCenterX
btnClick.y = display.contentCenterY

if (user.penLevel > 0) then
penLevelImage:removeSelf()
end

--[[if (user.penClicks >= 20) then
	if (user.penLevel > 0) then
		user.penLevel = user.penLevel + 1
		penLevelImage:removeSelf()
	end
end]]

return main

Basically my question is, is it possible to update a text string live? If so how?




[topic_controls]
[/topic_controls]