Coming back to Codea

Hello,

I am coming back to Codea after a while (looks like the last time was in 2020). At the time I had a folder called “data” in my project and I used:
local data = readText(“Project:” … myDataFolder … filename)

To read a text file from this folder.

Now it looks like you can read static asset with a static : asset.document…. And not a string anymore.
How can I read an asset by building the name dynamically?

Thanks !

@dlpnet - you can build a path to the asset like

Path = asset.documents.directory

Then use

Txt = Path … “filename”

Think that’s right, not on my pad to check.

@dlpnet Here’s some examples.

function setup()
    name1="Dropbox.assets"    
    name2="/test910.txt" -- needs leading / and file extension       
    str=readText(asset.documents..name1..name2)
    print(str)
    
    name3="/Character Cat Girl.png" -- don't use underscores in name, use spaces instead
    img=readImage(asset.builtin.Planet_Cute..name3)
end

function draw()
    background(0)
    sprite(img,WIDTH/2,HEIGHT/2)
end

@dpnet - just picked up my pad and noted @dave1707 post. I’ve added the method I often use - that is a table of file names required and a path including the directory name. Note files enclosed as text.


-- file addressing 1

function setup()
    --
    parameter.integer("img",1,#files,1)
    path = asset.documents.NoNoResP  -- note NoNoResP is my asset directory -  inot using asset in the directory name.
end

function draw()
    -- 
    background(40, 40, 50)
    sprite(path..files[img],WIDTH/2,HEIGHT//2)
end

files = {
        "buttonN",
        "buttonP"
        }

Hope that is clear.

With the 2 examples I made it work. Thank you both