Codea 3.1 (208)

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

One would naively expect that the provided examples would work … :slight_smile:

and if this one did it would be delightfully informative!

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

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

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

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 …

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

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

@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

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

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?

@Simeon - before describing what happened here my apologies, saw this and couldn’t resist running it (yeah I’m weird):

@dave1707 reported a crash of Codea (in October last year) with the following code -:


function setup()
    xx="qwertyuiop"
end

function draw()
    background(0)
    xx=xx..xx  
end

function temp()
    print("temp")
end

I ran it and lo’ and behold - it crashed!!! No surprise. But, the project printed an error “not enough memory” (9 instances) which looked like you might have resolved it - one up for 2LL. But it didn’t, it totally hung up Codea. Closing Codea and re-running hung up again or crashed. The only way I could get out of this was to switch off my iPad and reboot. Is this still expected?

Posted here instead of editing errors thread as not known if this is an issue re-introduced in this beta.

@Bri_G @Simeon I saw that message a couple of days ago when I tried to crash Codea on purpose. I ran the below code which gave that message but didn’t cause and problems. When I got the message I could exit back to the editor and make changes.

PS. I ran the code that Bri_G shows above, but I don’t hang or crash. I can exit back to the editor.

displayMode(STANDARD)

function setup()
    str="qwert"
    for z=1,10000 do
        str=str..str
    end    
end

@dave1707 - after your message ran the code again and it came back with the same message with 20 repeats. It did re-run again coming back with 2 repeats ran it again 2 repeats again ran it again and it locked out Codea. Reset Codea ran again came up with message that Codea had crashed. Looks like there is some carryover from each error building up until Codea crashed.

@Bri_G I ran my code 30 times and Codea never locked up.

@dave1707 - used TestFlight to re-instal and ran without problem. Must have been some corruption. Thanks.

@Simeon Not a problem, just curious about this. If I run this code, it displays 13956 lines of the alphabet. If I increase the count by 1 to 13957, it doesn’t print the alphabet. If I cut the string in half so 2 print on a single line then I can increase the count to 27912. So it appears that print has a limit of what it can print in one group, that being 13956.

function setup()
    tab={}
    str="abcdefghijklmnopqrstuvwxyz"
    for z=1,13956 do
        table.insert(tab,str)
    end
    print(table.concat(tab," "))
    print(#tab)
end

@dave1707 - did you at any time get the ‘not enough memory’ message? ie is there a self imposed limit?

@Bri_G If you’re referring to the above code, no, I didn’t get the memory message. It uses less than 363,000 bytes of memory for the info in the table. Maybe I’ll try to get a byte count that causes the memory message.

@dave1707 - a byte count could be useful. That’s an odd number for the info in the table.