Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Runtime error with IO file
Started by fferraro67 Jul 09 2019 03:33 PM

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

fferraro67

[GLOBAL: userInfoPane.html]
fferraro67
  • Contributor

  • 242 posts
  • Corona SDK

In the simulator it works perfectly. The error appears on the ipad.

 

 

--Runtime error

--line 11185: attempt to index global "file" (a nil value)
 
 
 
function Leer (event)
path = system.pathForFile( "Preferencias.txt" )
file = io.open( path, "r" )
CadenaPreferencias= file:read("*a")
io.close( file )
  
    VP1=(string.sub(CadenaPreferencias, 1, 1))  
    VP2=(string.sub(CadenaPreferencias, 2, 2))  
    VP3=(string.sub(CadenaPreferencias, 3, 3))  
    VP4=(string.sub(CadenaPreferencias, 4, 4))  
    VP7=(string.sub(CadenaPreferencias, 5, 5))  
end
 
function Escribir (event)
CadenaPreferencias=(VP1..VP2..VP3..VP4..VP7)
path = system.pathForFile( "Preferencias.txt" )
file = io.open( path, "w" )
file:write(CadenaPreferencias)
io.close( file )
end
 
 
 
-- the line with red text is line 11185
 
Its a scope problem?


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,788 posts
  • Enterprise

You may be trying to write to system.ResourcesDirectory which is read-only. You need to specifically select system.DocumentsDirectory for writing files like preferences too.

 

Rob




[topic_controls]
[/topic_controls]