You would need a text field and a saving function. Once they enter text, it will save the text they entered to a text file in which they can access from other documents. Simply load gameState to a variable then you can call if from all lua documents. Check out this short example I wrote up :
[lua]local json = require “dkjson”
function Load( pathname ) – load a table from a file, this is just one way to do saves
local data = nil
local path = system.pathForFile( pathname…".txt", system.DocumentsDirectory ) – get the file path
local fileHandle = io.open( path, “r” ) – open the file
if fileHandle then – if opening the file worked, read the file.
data = json.decode( fileHandle:read( “*a” ) ) – decode the JSON into a lua table
io.close( fileHandle ) – close the opened file
end
return data – return the loaded table
end
function Save( data, pathname ) – save a table to a file
local success = false
local path = system.pathForFile( pathname…".txt", system.DocumentsDirectory ) – get the file path
local fileHandle = io.open( path, “w” ) – open the file
if fileHandle then – if it worked write the file
fileHandle:write( json.encode( data ) ) – encode the table into JSON, then write it to file
io.close( fileHandle ) – close the file
success = true
end
return success – return true if it worked, false otherwise
end
userNamo = Load( “gameState” )
enterName = native.newTextField( 50,150,500,60)
local function onTyped(event)
if (event.phase == “submitted” or event.phase==“ended”) then
native.setKeyboardFocus(nil)
userNamo = enterName.text
Save( userNamo, “gameState” ) --Save the text to a text file called “gameState” now from a different document, you can make sure that the gameState text matches.
end
end
enterName:addEventListener(“userInput”, onTyped)
submit:addEventListener(“touch”, onTyped)
–Special thanks to Angelo Yazar for writing the saving and loading function[/lua] [import]uid: 29181 topic_id: 24598 reply_id: 99678[/import]