Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I/O questions. f=file.open("test.txt","w") print(f) --nil

Was going to try learning the I/O stuff. But, im not sure, does codea support it? I do this in codea, but nothing i did worked. Maybe im making a dumb mistake.

f=io.open("test.txt", "w")
print(f)    --nil

Comments

  • em2em2
    Posts: 194

    The code you posted is not enough to determine your problem, but test.txt probably doesn't exist. You need to read it from the documents folder. Try this, in a project named "IOtest" (it must be named IOtest exactly):

    path = os.getenv("HOME") -- Get codea's home directory
    path = path.."/Documents" -- move to the Documents folder (where all projects are stored)
    path = path.."/IOtest.codea" -- move into this project
    path = path.."/Info.plist" -- read project info
    file = assert(io.open(path)) -- open file, check for errors
    content = file:read("*all") -- read file content
    print(content)
    
  • em2em2
    Posts: 194

    A quick forum search for "io" turned up this link.

  • dave1707dave1707 Mod
    Posts: 7,468

    @xThomas Try doing a search for io.open. I did a lot of file io examples a long time ago. You need to use a path name for the directory the file is in.

  • em2em2
    Posts: 194

    The link I posted has a couple of your examples, @dave1707 .

  • Posts: 808

    If you want IO for saving something, I'd suggest you to take a look at the Bit Invader Example.

    readLocalData(str)
    saveLocalData(data, str)
    

    str is the keyword, how you saved it, data is the object you want to save. Example:

    function setup()
          if readLocalData("obj") then
                print("Data:" .. readLocalData("obj"))
          end
    
          parameter.text("String")
          parameter.action("Save", function() saveLocalData(String, "obj") end)
    end
    

    This example will open your project, and any text you enter in the parameters and displayed when reopening it.

  • marking for use later

Sign In or Register to comment.