Howdy, Stranger!

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

Codea 3.1 (208)

dave1707dave1707 Mod
edited March 15 in Beta Posts: 8,387

@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.

«1

Comments

  • SimeonSimeon Admin Mod
    edited March 13 Posts: 5,362

    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
    
  • dave1707dave1707 Mod
    Posts: 8,387

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

  • dave1707dave1707 Mod
    edited March 14 Posts: 8,387

    @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
    
  • SimeonSimeon Admin Mod
    edited March 14 Posts: 5,362

    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
  • dave1707dave1707 Mod
    edited March 14 Posts: 8,387

    @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
    
  • SimeonSimeon Admin Mod
    edited March 14 Posts: 5,362

    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

  • dave1707dave1707 Mod
    Posts: 8,387

    @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.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @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.

  • dave1707dave1707 Mod
    Posts: 8,387

    @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.

  • dave1707dave1707 Mod
    edited March 14 Posts: 8,387

    @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
    
  • SimeonSimeon Admin Mod
    Posts: 5,362

    @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

  • dave1707dave1707 Mod
    Posts: 8,387

    @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.

  • SimeonSimeon Admin Mod
    Posts: 5,362
    @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
  • dave1707dave1707 Mod
    Posts: 8,387

    @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.

  • Posts: 1,708
    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.
  • SimeonSimeon Admin Mod
    Posts: 5,362
    @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
  • dave1707dave1707 Mod
    edited March 16 Posts: 8,387

    @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
    
    
  • SimeonSimeon Admin Mod
    edited March 17 Posts: 5,362

    @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

  • dave1707dave1707 Mod
    Posts: 8,387

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

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 is there a particular thing you're doing where having the name is more convenient?

    For now you could write an extension to string to get no extension:

    function string.noExt(str)
        local rev = string.reverse(str)
        local pos = string.find(rev, ".", 1, true)
    
        if pos then 
            return string.sub( str, 1, #str - pos ) 
        else 
            return str
        end
    end
    

    Then do string.noExt(b.name)

  • dave1707dave1707 Mod
    Posts: 8,387

    @Simeon I don’t do anything important, just mostly write code for something to do. It’s just the old way used to give the name without any extensions, so I thought the new way could too. I do something similar to what you show above to remove the extension. I just thought since you have .ext, .type, .path, .name, it would be just as easy to have one with just the name. If not, then I’ll just continue to strip off the extension with code like you have above.

  • dave1707dave1707 Mod
    Posts: 8,387

    @Simeon Heres what I use to get just the name. So if you don’t want to make any changes, that’s OK.

    function nameOnly(name)
        st=string.find(name,".",1,true)
        if st then
            return string.sub(name,1,st-1)
        end
        return name
    end
    
  • edited March 17 Posts: 1,708

    @Simeon - had a weird crash in Codea. I pasted a few lines from a draw() function in a small project to a new blank project draw() function. There were a couple of variables in text() functions to define text positions. I ran the code before defining the variables and Codea crashed. I repeated this and it crashed again. I had to shut down my iPad at that point. Returning to it later and trying to duplicate it resulted in the expected errors of undefined variables. I have not been able to repeat this.

    Prior to the crashing I was working on presenting backup file details, a la @dave1707 utility, pasting information into Codea tabs. During that I had to use Save & Run to stop losing edits. Could that have been behind the crashes?

    One other thing I noticed, on the backup listings into tabs, most of the tabs had —[[ —]] commenting surrounding output in the tabs. Some of the commenting didn’t work sometimes sporadically other times all text not commented out.

  • SimeonSimeon Admin Mod
    edited March 18 Posts: 5,362

    @dave1707 the reason I reversed the string first is because I wanted to search "." from the end of the string, in case of a file name like foo.bar.txt (the extension there is txt and name is foo.bar)

    @Bri_G sorry about the crash, the Save & Run step is something I'd really like to fix. I have a note to look into the code around saving and will do so

  • dave1707dave1707 Mod
    Posts: 8,387

    @Simeon I wondered why you reversed it, never thought of that.

  • edited March 18 Posts: 1,708

    @Simeon @John @dave1707 - just noticed a funny whilst programming. Had my Mac and iPad running and searching on the Mac for graph plotting. I have recently downgraded from Catalina to Mojave as too many clashes and issues with Catalina. One feature Catalina introduced was the use of the iPad as a second screen - which, appeared to introduce a small icon representing the iPad next to the toolbar. This appeared on my Mac. Daft, but I thought I wonder if you have other links with this so I selected and copied some code from the forum (on my Mac) - opened a new project on Codea and told it to paste - it did!!! Is this a feature? Why is it on Mojave? If so how can I raise the iPad icon next to the toolbar as it seems to have disappeared?

    Edit: tried again without the icon and the transfer worked.

    Edit 2: Just downloaded a file from an old Dropbox project into Visual Studio Code on my Mac. Opened a new project up on my iPad selected the code on my Mac and pasted into my iPad - yippee - goodbye Air Code this is awesome.

  • edited March 18 Posts: 1,708

    @Simeon - sorry to be a pain with this but I have an issue with dependencies - that is all of my projects are presented in the list and It takes me ages (sometimes) to find the project I wish to link dependencies to. So I have a suggestion:

    Don't add all projects to the dependencies. Instead have an entry to the options when you long press on a project to 'Add to Dependencies'. In this way you can put libraries etc that you wish to use regularly and have a relatively short list. Also, what may be useful, is if you add an option in the dependency list for each dependency project to be removed from the list.

    Not a burning issue but I think it could improve Codea.

  • edited March 18 Posts: 1,708

    @Simeon - got my thinking cap on at the moment and a thought flashed though what's left of my grey matter. Looking at Xcode again I began to wonder if the full Codea package is part of the engine transferred with each development package - so Craft would be included and the other libraries used within Codea. If so - does that make the resultant Xcode project pretty bulky? If so could you have support libraries etc selectable for export in an effort to reduce the final project size? Just thinking of trying to minimise issues on iPad's with low memory - is that an issue? If not ignore this post.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @Bri_G that feature you describe is called "Universal Clipboard" which has actually been around since OS X Yosemite (!). I use it all the time and it's one of the best features ever

    Note that it works for images and video too. Often I'll copy a screenshot on my iPad and paste right onto mac, or the other way around

    Agreed on the dependency list. It should have an add button that lets you pick, rather than showing everything with a check box

    On the Xcode app size, it does add some overhead to have those frameworks but not as much as you'd think. They are quite big to download, but the resulting app size is still reasonably small. I'll keep it in mind though

  • Posts: 1,708

    @Simeon - thanks for the info on "Universal Clipboard" wasn't aware of that feature. May have been included when I reinstalled Mojave but it means editing code gets much easier now. Thanks.

  • Posts: 580

    in 3d asset viewer example, what is the non-deprecated replacement for

    assets = assetList(pack, "models")
    

    i tried

    assets = asset.builtin[pack].all
    

    but the .all is sent to nil when pack is "Blocky Characters".

    relatedly there's nothing in the docs about this. when you search for "asset" you get function assetList, and when you click that, nothing.

    i'll help with this if i can.

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries Here’s something that lists models in Nature. When you try to get things listed, in the code, key the word asset followed by a period. Then autocomplete will give you a list of what can come next. Select something from the list, then key a period and autocomplete will give another list of what’s valid.

    displayMode(STANDARD)
    
    function setup()
        a=asset.builtin.Nature.all
        for a,b in pairs(a) do
            print(b.name)
        end
    end
    
  • Posts: 580

    note what the asset viewer example is doing. it has the asset group name as strings. so it'd have to be subscripted. but asset.builtin is a user data, i think, so, i'm guessing, subscripting doesn't work.

    relatedly, if in that example you change Blocky Characters on line 14 to Blocky_Characters, you get a hard crash.

    should we move this to bugs? seems ok here to me ...

  • Posts: 580

    guessing here that this example needs to select only .obj and proceed from there, possibly trimming the names. there seems to be no direct way to select just models as assetList does.

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries What asset viewer example are you referring to.

  • edited March 21 Posts: 1,708

    @RonJeffries - try this:


    function setup() -- a=asset.builtin.Nature.all for a,b in pairs(a) do if b.ext == "obj" then print(b.name) end end end

    Note: @dave1707 has already mentioned the issue of .ext inclusion in .name and @Simeon is looking into it.

  • Posts: 580

    3d asset viewer example in craft examples

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries OK, found it. I was playing with 3D asset viewer and you’re correct, I didn’t see an easy way to select just the models. Maybe that’s why the example puts out the warning.

  • Posts: 580

    well all use of assetList does that, i think

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries The example 3D asset viewer is the only example that uses assetList that I found. If you use assetList in your code, then you’ll have to modify it to use the new way depending on how you use it. So I can’t give you a specific way to do it.

  • edited March 21 Posts: 580

    One would naively expect that the provided examples would work ... :)

    and if this one did it would be delightfully informative!

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries I don’t know if it would help that much. How assets are used is different depending on what you’re doing with them. Maybe looking at recent examples would be more helpful. There could be a better mix of how the assets are being used. I spent a couple of hours modifying all of my projects to the new layout. Some of the changes were easy while some took a while to get it to work.

  • Posts: 580

    the recent examples of which you speak ... can you recommend some?
    the documentation for using asset ... is there any?

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries Look for the discussion Codea 3.1 (203). Page 1 gives a lot of info.
    There some docs in the reference at Graphics/Overview/Using Assets.

  • Posts: 580

    i'll do that. the docs you ref say to type assets, which should be asset, and when you search for asset, that info is not found ...

  • dave1707dave1707 Mod
    Posts: 8,387

    @RonJeffries assets was later changed to asset. So what you see in the doc for assets is really for asset.

  • Posts: 580

    yes. i'm reporting issues that need fixing. mostly not stuck, yet. :smile: will be soon, i imagine ...

  • SimeonSimeon Admin Mod
    edited March 22 Posts: 5,362

    @RonJeffries oh I did miss the use of assetList in 3D Asset Viewer when I went through an updated all the examples for the new API. Sorry about that, I'm collating bugs to fix for v3.1.1 so thank you for reporting them

    Here's a fixed version of the 3D Asset Viewer:
    https://gist.github.com/TwoLivesLeft/a751d1ae6b1e77f5271ea0c4ccd00500

    To go through the changed lines:


    -- This function now takes an asset key for the pack, instead of a string function loadModels(pack) -- Filter the contents of this pack just to get 3D models local modelList = {} for _,v in pairs(pack.all) do if v.type == MODELS then table.insert(modelList, v) end end

    Later on in the function loadModels:


    -- Load models models = {} for _,v in pairs(modelList) do local model = scene:entity() local mr = model:add(craft.renderer) -- Here we can just load the asset "key" directly -- don't need the string version ("Pack:Name") mr.model = craft.model(v) -- Tag the model for later model:add(Tag, pack.name..":"..v.name) table.insert(models, model) end

    We need to update the names of the packs at the start in setup():


    packs = { asset.builtin.Blocky_Characters, asset.builtin.Watercraft, asset.builtin.RacingKit, asset.builtin.SpaceKit, asset.builtin.CastleKit, asset.builtin.Primitives, asset.builtin.Nature }

    Doing it this way you will get autocompletion on the asset packs, and if you edit one of those names to be incorrect Codea will mark it as an error in the editor so you know that the file doesn't exist

    For example, try changing asset.builtin.Blocky_Characters to asset.builtin.BlockyCharacters

    Side note:
    If you wanted to reference these by their proper file name then you could do so as follows:

    asset.builtin["Blocky Characters.assets"]

    Since if you use bracket indexing you need the actual filename that is on disk, which has a .assets extension for these folders

  • Posts: 580

    yes, better. i'll have to study that a bit, it has some twists. thanks!

  • edited March 22 Posts: 580

    ooo ... what is `scene.debug'???
    and model.bounds?
    is there some way to find the methods of a userdata like these. bounds understand min and max? and offset? and what is bounds on 129? seems to be a function, but where defined?

    and why does backtick turn into 1st?

Sign In or Register to comment.