Howdy, Stranger!

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

Asset naming to copy tabs from one project to another

in Questions Posts: 1,089

In some recent thread, it was suggested to use readText and saveText, rather than readProjectTab and saveProjectTab. I'm looking for hints on how to do that so as to satisfy the compiler and have it actually work.

Suppose we have the text name of a project in documents. "MTarget" is the name.

We can't say local proj = asset.documents.."MTarget". We get a run-time error saying attempt to concatenate a userdata value.

If we knew the name of the project at compile time we could say local proj = asset.documents.MTarget, but what do we say when we don't know the name at compile time?

Advice welcome. Thanks!


  • dave1707dave1707 Mod
    edited May 29 Posts: 9,432

    @RonJeffries I thought that’s how we were supposed to use assets for an asset that didn’t exist yet. When I put that line in a project, I don’t get any type of error.

    local proj = asset.documents.."MTarget"

    works for me.

  • Posts: 1,089

    hm, i'll go look, maybe a typo i'm missing, thanks

  • Posts: 1,089

    I was misrepresenting the problem. I'm trying to get to the point where I can write to a new tab in a different project, whose name I have as a string.

    The code I'm using is this:

                local xxx = asset.documents.Files.all
                local yyy = asset.documents
                yyy = yyy.."MTarget"
                for i,v in pairs(xxx) do
                    if".lua") then
                        print (i,, v.type) 
                        local txt = readText(v)
                        local toWrite =
                        print("write ", toWrite)

    It is the concat that doesn't work. However, and this may get me where I need to go, this does work:

                        local toWrite = asset.documents.."MTarget"

    It seems that you cannot save a partially concatenated asset name and then concatenate to it, but you can concatenate twice.

    So, I think I can work with this but it seems quite odd.

    Thanks, I shall press onward ...

  • edited May 29 Posts: 1,089

    Update: that asset with two concats executes but has no dot in between MTarget and, so the saveText goes off into space. I'll try putting one in explicitly.

    OK that doesn't work either. You're writing to this:

    Asset Key: MTarget.Tests.lua (path: "/var/mobile/Containers/Data/Application/8237698C-306E-444D-BA10-95B7089EF5DA/Documents/MTarget.Tests.lua")

    And that's not the right name. One would have to change the name to Tests_lua? or Tests? I don't know.

    I'd like to see a working example of accepting two project names and copying all the tabs from the one to the other, using readText and saveText.

    So far, the suggestion that read and saveText will suffice may be true, but it sure isn't straightforward like the read and save project tab stuff.

    Perhaps I'm missing some obvious thing: I often do.

  • Posts: 196

    @RonJeffries Could I suggest what WebRepo does:

    local asset_path = asset.documents .. “ProjectName.codea/TabName.lua”
    -- Write directly to the file
    local file =, "w")

    The file will only appear if the tab is already added to the target project (manually of saveProjectTab) but should work correctly to write to the correct file.

  • dave1707dave1707 Mod
    Posts: 9,432

    @RonJeffries Here are the readtext and savetext lines of code I use in my project backup code. The backupName in savetext is created on the fly based on the date and time that I do the backup. The name in readtext is also a variable name that gets selected from a list of backups.

  • dave1707dave1707 Mod
    Posts: 9,432

    @RonJeffries Heres something I just thru together to copy tabs from “input” and creating and saving the tabs in “output” after pressing copy.

     function setup()
    function copy()
        if #lst>0 then
            if hasProject(output) then
                print("project already exists")
                for a,b in pairs(lst) do
                    print(b.."  copied")
                print(output.."  created")
  • Posts: 1,089

    @dave1707 yes, can use the project tab code. Simeon said elsewhere, recently, that read and saveText sound suffice. maybe it's possible, but it's not pretty.

    @Steppers interesting. i'm writing code to add certain tabs to a project. so i think i'll stick with the project tab stuff. thanks!

Sign In or Register to comment.