Rob,
thanks for clearing up the value info, its more clear to me now how that works.
I’m currently using storyboard, but i haven’t setup any groups in the main.lua file
heres is my main.lua
-----------------------------------------------------------------------------------------
-- main.lua
-----------------------------------------------------------------------------------------
display.setStatusBar( display.HiddenStatusBar )
-- require controller module
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
storyboard.ice = require("ice")
local score = ice:loadBox( "score" )
local gameScore = score:retrieve("gameScore")
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local json = require( "json" )
function saveTable(t, filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local file = io.open(path, "w")
if file then
local contents = json.encode(t)
file:write( contents )
io.close( file )
return true
else
return false
end
end
function loadTable(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local contents = ""
local myTable = {}
local file = io.open( path, "r" )
if file then
print("trying to read ", filename)
-- read all contents of file into a string
local contents = file:read( "\*a" )
myTable = json.decode(contents);
io.close( file )
print("Loaded file")
return myTable
end
print("file not found")
return nil
end
storyboard.loadTable = loadTable
storyboard.saveTable = saveTable
storyboard.settings = storyboard.loadTable("settings.json")
if storyboard.settings == nil then -- didn't load the table
storyboard.settings = {}
storyboard.settings.musicOn = true
storyboard.settings.soundFX = true
storyboard.settings.highScore = 100
storyboard.saveTable(storyboard.settings, "settings.json")
end
print ("Current HIGH SCORE:", storyboard.settings.highScore)
storyboard.settings.highScore = storyboard.settings.highScore + 25
storyboard.saveTable(storyboard.settings, "settings.json")
print ("HIGH Score updated to:", storyboard.settings.highScore)
local highScoreText = display.newText(string.format("%03d", storyboard.settings.highScore), 0, 0, "Helvetica", 22)
highScoreText.x = display.contentWidth - 50
highScoreText.y = 300
--group:insert(highScoreText)
local scoredata
--[[ uncomment out below four lines to remove FPS status
local fps = require("fps")
local performance = fps.PerformanceOutput.new();
performance.group.x, performance.group.y = 50, 0;
performance.alpha = 0.2; -- So it doesn't get in the way of the rest of the scene
--]]
score:storeIfNew("gameScore", 100)
score:save()
print( "Main: Current Score is:", gameScore )
scoredata = display.newText( "SCORE: " .. score:retrieve( "gameScore" ), 0, 0, "Helvetica", 22 )
scoredata.x = 70
scoredata.y = 300
-- load first screen
storyboard.gotoScene( "intro", "fade", 1000 )
intro.lua
---------------------------------------------------------------------------------
-- Intro Screen
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
storyboard.ice = require("ice")
local score = ice:loadBox( "score" ) -- this (loading the ice box locally) is what was missing!!
local gameScore = score:retrieve("gameScore")
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local background
-- Called when the scene's view does not exist:
function scene:createScene( event )
local screenGroup = self.view
background = display.newImage( "assets/graphics/intro.png", 0, 0 )
screenGroup:insert( background )
print( "\nIntro: createScene event")
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print( "Intro: enterScene event" )
print( "Intro Current Score is:", gameScore )
gameScore = gameScore + 5
score:store("gameScore", gameScore)
score:save() -- this will finally work!
print( "updated score is:", gameScore )
print ("Current HIGH SCORE:", storyboard.settings.highScore)
storyboard.settings.highScore = storyboard.settings.highScore + 10
storyboard.saveTable(storyboard.settings, "settings.json")
print ("")
print ("Intro Scene HIGH Score updated to:", storyboard.settings.highScore)
highScoreText.text = string.format("%03d",storyboard.settings.highScore)
local function gotoTitle()
storyboard.gotoScene( "title", "fade", 500 )
end
-- To wait 3 seconds before switching scenes,
timer.performWithDelay(1500, gotoTitle)
local lastScene = storyboard.getPrevious()
print( "last scene was:", lastScene ) -- output: last scene name
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print( "Intro: exitScene event" )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print( "((destroying Intro's view))" )
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
I’ve been testing my file with both this method and ice box to see which one works, as I’ve had issues getting icebox to pass data and update to the text box.
now in the updating code you provided
highScoreText.text = string.format("%03d",storyboard.settings.highScore)
should i have included the
group:insert(highScoreText)
to update the score to the text ? as I’m not getting the score updated in real time, its updating it via the print command but not on the highScoreText
when i run the code like this i get the following errors
Runtime error
…/emanouel1979/CoronaProjects/Haunted House/intro.lua:42: attempt to index global ‘highScoreText’ (a nil value)
stack traceback:
[C]: ?
…/emanouel1979/CoronaProjects/Haunted House/intro.lua:42: in function <… house>
?: in function ‘dispatchEvent’
?: in function <?:1095>
(tail call): ?
?: in function <?:1170>
?: in function <?:218>
[import]uid: 17701 topic_id: 25923 reply_id: 107443[/import] </…>