Peach, thank you for the Ego library!
I’m working on the sample code, to understand/learn the Ego library 
So far I got a second score to work
But the textfield is not working… The input text will not be saved in the text file.
I think the problem is:
-- Add defaultField
local defaultField = ""
The full code:
[code]–Hide the status bar
display.setStatusBar(display.HiddenStatusBar)
–Saving/Loading Stuff
local ego = require “ego”
local saveFile = ego.saveFile
local loadFile = ego.loadFile
–Create the background and make it blue
local bg = display.newRect( 0, 0, 320, 480 )
bg:setFillColor( 150, 180, 200 )
–Start the score at 1
local score = 1
– Add score2
local score2 = 2
–Create score text and make it dark gray
local scoreText = display.newText(score, 200, 20, native.systemFont, 24)
scoreText:setTextColor( 80, 80, 80 )
– Add score2
–Create score text and make it dark gray
local score2Text = display.newText(score, 200, 20, native.systemFont, 24)
scoreText:setTextColor( 80, 80, 80 )
– Add defaultField
local defaultField = “”-- forward reference (needed for Lua closure)
– TextField Listener
local function fieldHandler( getObj )
– Use Lua closure in order to access the TextField object
return function( event )
print( "TextField Object is: " … tostring( getObj() ) )
if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event
elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field:
– for example, when they touch a different field or keyboard focus goes away
print( "Text entered = " … tostring( getObj().text ) ) – display the text entered
elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key
– (if available) on the onscreen keyboard
– Hide keyboard
native.setKeyboardFocus( nil )
end
end – “return function()”
end
– Add defaultField
defaultField = native.newTextField( 10, 30, 180, 30,
fieldHandler( function() return defaultField end ) ) – passes the text field object
–Function to add to score and update scoreText
local function addToScore()
score = score + 1
scoreText.text = score
end
bg:addEventListener(“tap”, addToScore)
–Load highscore value from file. (It will initally be a string.)
highscore = loadFile (“highscore.txt”)
– Add score2
score2 = loadFile (“score2.txt”)
– Add defaultField
defaultField = loadFile (“field.txt”)
–If the file is empty (this means it is the first time you’ve run the app) save it as 0
local function checkForFile ()
if highscore == “empty” then
highscore = 0
end
–Add score2
if score2 == “empty” then
score2 = 4
end
–Add defaultField
if defaultField == “empty” then
defaultField = “text is empty”
saveFile(“highscore.txt”, highscore)
– Aad score2
saveFile(“score2.txt”, score2)
– Add defaultField
saveFile(“field.txt”, defaultField)
end
end
checkForFile()
–Print the current highscore
print (“Highscore is”, highscore)
– Add score2
print (“Score2 is”, score2)
– Add defaultField
print (“defaultField is”, defaultField)
–When the app is quit (or simulator refreshed) save the new highscore
–(If score > highscore the data will not be changed)
local function onSystemEvent ()
if score > tonumber(highscore) then --We use tonumber as highscore is a string when loaded
saveFile(“highscore.txt”, score)
– Add score2
saveFile(“score2.txt”, score2)
– Add defaultField
saveFile(“field.txt”, defaultField)
end
end
Runtime:addEventListener( “system”, onSystemEvent )[/code]
[import]uid: 150924 topic_id: 27333 reply_id: 111317[/import]