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?
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"
}