Codea 3.1 (208)

@Simeon The new asset.all is kind of useless. This is just one of the items that’s in the table for temp=asset.documents.Craft.all. If I want the name I have to do a lot of messing around to pull the name out of that.

Asset Library: 3D Asset Viewer.codea (path: “/private/var/mobile/Containers/Data/Application/09E04C63-C50D-43F7-A91D-C9AA296E1E01/Documents/Craft/3D Asset Viewer.codea”)

PS. I think you pulled out the path name instead of the key name.

To get the name you just do .name on the result

for _,v in pairs(asset.documents.Craft.all) do
    print(v.name)
    print(v.ext)
    print(v.path)
end

@Simeon OK, thanks. That make things a lot easier. I seen those, but I never tried to use them.

@Simeon I changed my projects to use the new asset.all function but I ran into problems with one project. Here’s a stripped down version of the code.

1.) I had to replace any space in the name with an underscore.
2.) I had to strip off the extension names.

Is there a way to not replace spaces or remove extension names. If not I can always create a function to do it.

function setup()
    -- read obj files
    tab1=asset.builtin.all  -- list of assets
    for a,b in pairs(tab1) do
        bn=b.name
        tab2=asset.builtin[bn].all   -- list of asset files
        for c,d in pairs(tab2) do
            if d.ext=="obj" then
                
                print(bn)   -- asset name
                bn=string.gsub(bn," ","_")  -- replace any space with underscore
                print(bn)   
                bn=string.sub(bn,1,#bn-7)   -- remove .extension
                print(bn)
                   
                n=d.name    -- file name
                print(n)    
                n=string.sub(n,1,#n-4)  -- remove .extension
                print(n)
                
                str=readText(asset.builtin[bn][n])
                print(str)
                
                stop()  -- cause error to stop after printing first file
                
            end            
        end
    end
end

That’s really strange, you shouldn’t have had to do that!

This code works for me (in that it prints the first object before stopping)

function setup()
    -- read obj files
    tab1=asset.builtin.all  -- list of assets
    for a,b in pairs(tab1) do
        bn=b.name
        tab2=asset.builtin[bn].all   -- list of asset files
        for c,d in pairs(tab2) do
            if d.ext=="obj" then

                print(bn)   -- asset name
                n=d.name    -- file name

                str=readText(asset.builtin[bn][n])
                print(str)

                stop()  -- cause error to stop after printing first file

            end            
        end
    end
end

Note that you could also rewrite this:

function setup()
– read obj files
tab1=asset.builtin.all – list of assets
for a,b in pairs(tab1) do
bn=b.name
tab2=asset.builtin[bn].all – list of asset files
for c,d in pairs(tab2) do
if d.ext==“obj” then

            str=readText(d)
            print(str)

            stop()  -- cause error to stop after printing first file

        end            
    end
end

end

@Simeon Heres an updated version for my above code. I was able to eliminate a lot of code.

function setup()
    -- read obj files
    tab1=asset.builtin.all  -- list of assets
    for a,b in pairs(tab1) do
        tab2=asset.builtin[b.name].all   -- list of asset files
        for c,d in pairs(tab2) do
            if d.ext=="obj" then                
                str=readText(d)
                print(str)                
                stop()  -- cause error to stop after printing first file                
            end            
        end
    end
end

Sorry I edited my post after you posted. You don’t need to strip the names and replace characters, is that right?

Just a note that you’d probably want to change the line

tab2=asset.builtin[b.name].all

to

tab2=asset.builtin[b.name].all or {}

Because tab2 will be nil if the asset referenced by b.name is not a folder

@Simeon That’s correct, I don’t need to do any stripping. I was able to remove a lot of code from my original code using the new asset.all code. I wasn’t expecting you to respond because I thought you would be sleeping. I can’t seem to figure out your wake/sleep schedule compared to mine.

@dave1707 it’s 3 am here. I was hoping to sleep earlier but kept trying to fix just one more bug.

Normally I’m on Adelaide time for South Australia.

@Simeon Thats what I thought, you’re normally sleeping while I’m awake. I’m on EST (right now DST, daylight savings time) for eastern USA.

@Simeon Version 205. This is a nothing problem, but in the code below, if I put the cursor on one of the middle color lines, the color icon doesn’t show on the line just above or just below which is probably what you want. If the line has one value in the (), the color icon doesn’t show one line above or below. If there are 2 or more values, then the color icon does show on the line just above and below. Like I said it a nothing problem.

PS. The cursor has to be to the right of the color icon. It’s different if it’s left of it.

function setup()
    color()
    color()
    color()
    color()
    color()
    color()
    color()
    color()
end

@dave1707 the way this works is Codea checks whether the cursor would overlap the colour annotation (with some extra padding) and if so it hides those annotations so you can read the code there

@Simeon Version 208.

You haven’t fixed the search problem yet.

  1. Do a search for something.
  2. Tap on the found word to take you to a line where it’s found
  3. Close the search window.
  4. The found word in a yellow rectangle stays on the screen.

@dave1707 thank you for catching this. i was hoping to consider 208 for release but will see if i can squeeze this fix in too

@Simeon I’m not the one who found it. I just noticed you wanted to do a release and I knew this was still an issue.

Wooah - loaded 205 checked it out, went to sleep (unlike @Simeon) woke up and 208 !!!
The pace at the moment is frantic. Get a rest Simeon - give us chance to catch up.

@Bri_G just very keen to get it released out of beta, 208 is the version submitted to the app store. Hopefully no major bugs in it

@Simeon If I run the below code, it shows Name, Ext, Type, Path of the files in documents. What I don’t like is that Name also shows the extension. Can you change it so name returns only the name without the extension. There’s no hurry, but it would be nice and I don’t think it should affect anything.

displayMode(FULLSCREEN)

function setup()
    dy=-30
    dx=0
    textMode(CORNER)
    tab=asset.documents.all
end
    
function draw()
    background(0)
    fill(255)
    for a,b in pairs(tab) do
        text(b.name,20+dx,HEIGHT-a*25+dy)
        text(b.ext,250+dx,HEIGHT-a*25+dy)
        text(b.type,350+dx,HEIGHT-a*25+dy)
        text(b.path,450+dx,HEIGHT-a*25+dy)
    end
    rect(0,HEIGHT-30,WIDTH,HEIGHT-30)
    fill(0)
    text("Name",20+dx,HEIGHT-25)
    text("Ext",250+dx,HEIGHT-25)
    text("Type",350+dx,HEIGHT-25)
    text("Path",450+dx,HEIGHT-25)
end

function touched(t)
    if t.state==MOVING then
        dy=dy+t.deltaY
        if dy<-30 then
            dy=-30
        end
        dx=dx+t.deltaX
        if dx>0 then
            dx=0
        end
    end
end

@dave1707 I considered this, but I did not do it because:

  • name can be used as the key for [k.name] indexing on an asset library
  • You may have multiple files with the same name and different extensions (obj.obj and obj.mtl come to mind)

On the other hand:

  • You can recreate the full name by doing name .. "." .. ext
  • You can differentiate between multiple files of the same name via extension or type

Perhaps I could move the full name into .filename and leave .name as the name minus extension?

I’m not really sure what to do here

@Simeon I like the .name and .filename options unless it will cause problems. Those two would be useable.