Search code examples
textlivecode

How do you save data from a text field to file on iOS and Android from a LiveCode?


I have various text fields within my LiveCode stack that I am trying to save to my mobile device. I have tried various methods but none seem to be working so far. The main script I am using trying to use from a button is-

on mouseUp
  put field "name" into ("file:"&specialFolderPath("engine")&"/name.txt")
end mouseUp

This doesn't seem to be working as if I try dome debugging with -

 on mouseUp
  answer there is a file ("file:"&specialFolderPath("engine")&"/name.txt")
 end mouseUp

It always returns false. Could you give me some pointers to what I am missing from my above script. Thanks.


Solution

  • You can't write to the engine folder on mobile devices. You should use the documents folder instead:

    on mouseUp
      put field "name" into URL ("file:" & specialFolderPath("documents") & "/name.txt")
    end mouseUp
    

    You may also write to specialFolderPath("cache") if the file is only temporary and you don't need it backed up. iOS also gives you the specialFolderPath("temporary") option.