how would i display text files value after using the systempath api
- Do you mean this function?: system.pathForFile( filename [, baseDirectory] )
- What do you my by ‘display’. Print to a log or show on the screen?
In either case, you have to read the text first. You could use my code here to do that:
function io.readFile( fileName, base ) local base = base or system.DocumentsDirectory local fileContents if( io.exists( fileName, base ) == false ) then return nil end local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end local f=io.open(fileName,"r") if (f == nil) then return nil end fileContents = f:read( "\*a" ) io.close(f) return fileContents end
Print To Log:
local contents = io.readFile( "myFile.txt" ) print( contents )
or use a text object to display it on-screen:
local contents = io.readFile( "myFile.txt" ) print( contents ) local options = { --parent = textGroup, text = contents , x = 100, y = 200, width = 128, --required for multi-line and alignment font = native.systemFontBold, fontSize = 18, } local myText = display.newText( options ) myText:setFillColor( 1, 0, 0 )
- Do you mean this function?: system.pathForFile( filename [, baseDirectory] )
- What do you my by ‘display’. Print to a log or show on the screen?
In either case, you have to read the text first. You could use my code here to do that:
function io.readFile( fileName, base ) local base = base or system.DocumentsDirectory local fileContents if( io.exists( fileName, base ) == false ) then return nil end local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end local f=io.open(fileName,"r") if (f == nil) then return nil end fileContents = f:read( "\*a" ) io.close(f) return fileContents end
Print To Log:
local contents = io.readFile( "myFile.txt" ) print( contents )
or use a text object to display it on-screen:
local contents = io.readFile( "myFile.txt" ) print( contents ) local options = { --parent = textGroup, text = contents , x = 100, y = 200, width = 128, --required for multi-line and alignment font = native.systemFontBold, fontSize = 18, } local myText = display.newText( options ) myText:setFillColor( 1, 0, 0 )