Howdy, Stranger!

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

Codea 3.1 (203)

SimeonSimeon Admin Mod
edited March 11 in Beta Posts: 5,362

A new beta is out with the new asset key API. This has been a work in progress for a while.

Basically the idea is to let the code editor know about the file system, the gist is instead of

"Project:My Sprite"

You now write

asset.My_Sprite

And get autocomplete for files which exist on your filesystem. There's a lot more to it (see the docs and release notes) but I'm keen to hear your feedback.

Anywhere you could use a string to specify an asset you should now be able to use an asset key instead, let me know if I've missed anywhere / broken your projects.

There's a couple other changes in this release

  • Changed editor font
  • Autocomplete should be significantly improved
  • Printing duplicate messages aggregates them in the output pane (i.e., no more spamming the same message in your draw loop)
  • Lots of bug fixes relating to how Codea terminates your projects
  • Lots of bug fixes with the parameter.* API
  • Adds timestamp to touch objects
  • Deprecates assetList
  • Craft supports HDR textures

Asset Keys

Asset keys are autocompleted identifiers in your code which refer to live files in your file system. If you type a key and the file doesn't exist, it's an error. Autocomplete will show completions for keys which are actually in your file system

Here's the API:

-- Refer to "MySprite.png" in the current project
asset.MySprite

-- Get a file in the Documents folder
asset.documents.MyFile

-- Get into a subfolder in your project
asset.FolderName.FileName

-- Get the icon for an example project
asset.documents.Examples.Flappy.Icon

-- Create an asset key for a new file in your project
local newAsset = asset .. "readme.txt"

-- ...or somewhere else
local newAsset = asset.documents .. "image.png"

-- Access our built-in sprite packs
asset.builtin.Planet_Cute.Icon

-- If you have multiple files in a folder with the same name, but different extensions, they'll have unique keys
local myModel = asset.model_obj
local myTexture = asset.model_png

-- If your file name has characters we can't use in a Lua identifier, then you need to use bracket indexing
asset.documents["My File (version 2).png"]

The above is all for referring to individual resources. If you refer to a folder, you get an asset library. This is an object which dynamically tracks the filesystem, you can list its contents and even receive notifications when the contents change

-- Get all the files in Documents 
local docs = asset.documents.all

-- Print all the files in your project
for k,v in pairs(asset.all) do
    print(k, v)
end

-- Get notified when the files in "MyFolder" change
asset.MyFolder.updated = function (lib)
     print("Library has " .. #lib .. " files")
end

-- Use '#' to get the number of files in an asset library
#asset
#asset.documents

-- Get the full path of an asset key or library
print(asset.path)
print(asset.Main.path)
«134

Comments

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Just started looking at the new version of Codea. So far I like the font in the editor. It’s a lot easier to read.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Ran into a problem. I created a new project and noticed that there were now two with the same name. The project didn’t exist before I created it. I can open the first one, but when I try to open the second one, the first one opens.

    Trying to figure out the new asset stuff. So far I just get errors.

  • dave1707dave1707 Mod
    edited February 12 Posts: 8,384

    @Simeon I deleted the second project, but now it won’t let me open the first one. Get a pop up that says Unexpected Error, Error creating or opening program. I now have a project I can’t open or delete.

    PS. I closed Codea and reopened it. The bad project is gone.

  • dave1707dave1707 Mod
    edited February 12 Posts: 8,384

    @Simeon Everytime I create a new project, I get 2 projects with the same name.

    PS. If I duplicate a project, I get 2 copies.
    PSS. If I close Codea and go back in, the 2nd copy is gone.

  • Posts: 1,705
    @Simeon - will install 3.1 shortly but little understanding first - are we talking local files here or can you include Dropbox?
  • dave1707dave1707 Mod
    edited February 12 Posts: 8,384

    @Simeon There give errors in the editor, but still run.

    print(assets.path)
    print(assets.Main.path)
    

    Are these assets changes for Codea or for Xcode. Because if I do print(assets.path) I get

    /var/mobile/Containers/Data/Application/6B98ADA7-BC9F-4726-ACF8-41D6F03F5A09/Documents/00d2.codea

    which doesn’t mean anything to me yet.

  • Posts: 1,705

    @Simeon - have you built in a level of backwards compatibility as the project @dave1707 built in ‘how might I build a die?’ modified by me with a series of sprites (same thread) worked without change.

    Further - tapping on sprite() for those sprites replaced the existing text with the new syntax. After doing so it allows you to use mixed syntax - see below works:


    sprite(assets.builtin.Blocks.Brick_Grey,150,50,100,100) sprite(assets.builtin.Blocks.Cotton_Red,150,150,100,100) sprite("Blocks:Cotton Tan",150,250,100,100) sprite("Blocks:Cotton Green",50,150,100,100) sprite("Blocks:Cactus Inside",250,150,100,100) sprite("Blocks:Cotton Blue",350,150,100,100)

    Just checking - I intend to adopt the new syntax - it seems more sensible in the long run.

    Does this push you to placing assets in the project folder (something I rarely do) as I tend to use Dropbox and Documents with table arrays of resource listings for source location.

  • edited February 12 Posts: 1,705

    @Simeon - trying to abbreviate the path result in a deviation, not an error. I used:


    A ABB = "assets.builtin.Blocks." sprite(assets.builtin.Blocks.Brick_Grey,150,50,100,100) sprite(assets.builtin.Blocks.Cotton_Red,150,150,100,100) sprite(ABB.."Cotton Tan",150,250,100,100) sprite("Blocks:Cotton Green",50,150,100,100) sprite("Blocks:Cactus Inside",250,150,100,100) sprite("Blocks:Cotton Blue",350,150,100,100)

    What happened is that the Cotton Tan image was not displayed but two Cotton Green were. Note I missed the underscore between Cotton and Tan initially but replacing the space with the underscore had no effect still two Cotton Green.

    Are we unable to abbreviate these addresses?

    p.s. I know this is just down to my bad programming habits but just now I’d like to understand the limits of the system.

  • edited February 12 Posts: 1,705

    @Simeon - the error on deprecation of sprite(path) in pre 3.1 presented in the slide out panel will only be seen if the author pulls it out. It just gives the number of the deprecation hits without line number. Trivial but the number presented partially obscures the error - would it be better to add an extra line with say ‘3 instances’ - just a thought.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 two projects! That sounds bad I'm sorry about the error just looking into it. I get the same issue, I must have broken something very recently as project creation was working OK before this. Thank you for the quick find

    The changes are for Codea.

    Unfortunately the real paths of files on iOS is ugly, but you can see that:

    /var/mobile/Containers/Data/Application/6B98ADA7-BC9F-4726-ACF8-41D6F03F5A09/Documents/00d2.codea

    Ends with

    /Documents/00d2.codea

    @Bri_G for your abbreviated example:

    local ABB = assets.builtin.blocks
    
    sprite(ABB.Brick_Grey, 150, 250, 100, 100)
    sprite(ABB.Cotton_Tan, 150, 250, 100, 100)
    -- etc
    

    Note that asset keys are not strings. The reason for using the .. syntax is to create a path to a new asset that doesn't exist:

    local newAsset = assets.documents .. "My Filename.png"
    
    print(newAsset.path)
    

    It does push you to placing assets in the project folder. But the next step is to allow folder references to be created in your projects. So the idea would be that you could add a folder reference from any cloud service (including Dropbox) to your project and it would sync automatically. Then I could remove the explicit Dropbox support from Codea.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon So far I’m not liking this release. I’m finding the assets stuff hard to work with, maybe because I don’t understand everything yet. I’ll post things as I try to convert some of my projects to the new assets. But here’s something that I don’t like, it’s the new print change. If I run the code below on an older iPad, it prints the 200 numbers and says it took .00095 seconds which I believe because it’s done by the time I get my finger off the screen. If I run that same code on my faster iPad Air 3, it says it took .000365 seconds. But I used a stopwatch to time it and it took 13.5 seconds before it finished. So did it take .000365 seconds to run but it took 13.499 seconds to print the numbers in the print area. I hope this doesn’t screw up the socket timer because I use it often to time routines.

        s=require("socket")
        st=s:gettime()
        for z=1,200 do
            print(z)
        end
        en=s:gettime()
        print(en-st)
    
  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 thank you for finding that print(assets.path) and print(assets.Main.path) shows as an error, it shouldn't. That's a bug

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 hmm thank you for the find on the print() slowness. I'd consider it a bug that it's so slow and will work to optimise it to be like before.

  • dave1707dave1707 Mod
    edited February 12 Posts: 8,384

    @Simeon I can’t figure out how to save a text file. I tried every combination I could think of, but it still doesn’t work. Some combinations don’t give editor errors, but give an error when I run the code.

    I can’t figure out what goes where I have ? marks below. I’m trying to save fileName in Dropbox with what’s in str.

        fileName="test1"
        str="this is a test string"
    
        saveText(assets.documents.Dropbox.????????,str)
    

    Also, the line below doesn’t cause an editor error, but crashes Codea. It doesn’t have the ) at the end of the line.

    saveText(assets.documents.Dropbox.test1,str
    
  • SimeonSimeon Admin Mod
    edited February 13 Posts: 5,362

    @dave1707 here's how you do it:

    saveText(assets.documents.Dropbox .. "test1.txt", str)
    

    Basically if you take an asset path to a folder (assets or assets.documents.Dropbox etc) then use the Lua append string operator (..) with a file name, it will generate an asset key to that path.

    The Image IO example project has been updated to show this exact functionality. Might be worth taking a look.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon I thought that was one of the things I tried. I tried your above example and received this.

    Main:14: bad argument #1 to 'saveText' (string expected, got userdata)
    stack traceback:
        [C]: in function 'saveText'
        Main:14: in function 'setup'
    
  • SimeonSimeon Admin Mod
    Posts: 5,362

    Looks like I have a bug in saveText, sorry about these issues and thank you for finding them. There have been a lot of changes to support this everywhere, this will be fixed next build.

    It should work like saveImage works

    I think these will be able to replace readProjectTab / saveProjectTab and friends. Because you could just do (when it's working!)

    local file = readText(assets.documents.Examples.Flappy.Main)
    
    saveText(assets.documents.MyProject .. "NewFile.lua", "-- hello world")
    
  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Thanks for the response, I’ll wait for the next update. Did you look into the other things I found farther up in this the discussion.

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

    Yes, the ones I've fixed for next build are
    - ghost project
    - saveText not working with asset keys
    - saveText line which crashes Codea
    - assets.path / assets.Main.path being incorrectly marked as error
    - slow output pane processing

  • Posts: 1,705

    @Simeon - loaded up the diecraft demo from the - how do I make a die - thread, the code from @LoopSpace . It crashes 3.1 when run.

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

    @Bri_G excellent, thank you

    I mean not excellent, but nice to find a crash

    Edit: It looks like possibly you need @LoopSpace's quat library installed, and there's a little bug where dieimg is declared a local variable in setup() but should be a global.

  • Posts: 1,705

    @Simeon - is this a recent bug, usually an error message is thrown up so we can trace the problem?

  • edited February 13 Posts: 1,705

    @Simeon @LoopSpace - thanks on the feedback, noted there is a bracket closure left out on the posted code. The project then runs and comes back with an error on random, when it is part of math.random??? The error throws up an issue I’ve raised before where random (pardon the pun) error messages are posted in a yellow box in various irrelevant pages (see photo attached) and photo of the error also attached.

    Further, tried to load @LoopSpace ’s math library by downloading zip then ‘sharing’ with Codea. Dialogue box opens to show contents of zip but with no text present so unable to import the library.

  • edited February 13 Posts: 1,705

    @Simeon @LoopSpace - think I am going to pass on this one for now, downloaded @LoopSpace ’s library into unzip, transferred to TextEditor then copied to Codea. So I have the library - but it threw up an error (photo attached) and I don’t want to get very deep into the library code as I think some of the issues may be addressing format with the cmodule.

    p.s. last post and this run with 3.1 (195)

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon I tested all the things you changed/add in the latest update. So far everything you mentioned works.

    Are the functions deleteProject and createProject supposed to work with the new assets stuff. When I try to use them I get an error message like

    Main:86: deleteProject requires a single project name as argument
    stack traceback:
    [C]: in function 'deleteProject'
    Main:86: in function 'setup'

    I can do saveProjectTab with the assets, but it doesn’t create the tab. I also don’t get any kind of an error message when it runs and no error in the editor.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 project creation and editing APIs have not been updated yet. I'm still looking into it but I think it would be nice if the asset keys worked with them too

    @Bri_G yeah that version of random is from the quat library and not part of Codea.

    And unfortunately downloading the zip from GitHub won't be a Codea project so Codea won't show it for import. Might look into adding functionality to allow you to import a zip of arbitrary files into a project.

  • Posts: 1,705

    @Simeon - the zip file does have an info.plist which is an Apple derived file. It also has a change log and a Data.plist but no icon file. Would the presence of the other plist files and/or the absence of the icon file negate proper download?

    Are you using calls to iOS systems to use that dialogue window ?

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon I was just messing around trying different things to see what would happen. When I tried print(#assets.updated) Codea crashed. It’s probably not valid, but it shouldn’t crash Codea.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Heres something that’s irritating me. The cursor keeps dropping to the bottom of the editor window as I’m typing things. It’s when I hit the keyboard somewhere between the double arrow, =, o, and p keys at the top right of the keyboard. There must be a dead spot somewhere between those keys that ignores the keyboard and moves the cursor. Open the editor and fill the screen with blank lines. Place the cursor at the top of the screen and just start tapping around those keys. Eventually the cursor will drop down and you be keying at the bottom.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @Bri_G Codea looks for folders called ".codea" inside the zip file when deciding how to show what to import. I think it would be great if we just supported any structure instead.

    @dave1707 thank you for finding that crash. Also thanks for the steps on the cursor bug, I'll try fix that one now

  • Posts: 489

    @Bri_G you only need the file called VecExt from my library.

  • edited February 14 Posts: 1,705

    @LoopSpace - thanks for the prompt, thought that adding library as a dependency would achieve the same but extracting out VecExt worked. Although out of interest I ran the library as it stands and it came back with an odd error (see the photo).

    @Simeon - a couple of points from this, I had used LoopSpace’s library as a dependency and when running it standalone I got a dependency error. I had not applied any dependencies to the library but there were two present one of which was the camera. Are dependencies applied and saved to the dependency file? I can’t think how it applied to the die. Also never seen the in-editor error experienced when I ran the complete library separately. Note also two other tabs indicating errors but could not find any on that tab? These files had been copied from a gist as a zip, opened with unzip and copied/pasted into Codea.

    Edit: edited out the 385 line with —[[ and —]] and the error disappeared. Also the errors on the other two tabs the appeared both with the following line highlighted involving cmodule:


    if cmodule.loaded "TestSuite" then

    Note - @LoopSpace - this is occurring in 3.1(195)

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon The print(#assers.updated) doesn’t crash Codea anymore and I can’t force the cursor to the bottom of the screen. So those fixes worked. The cursor problem was irritating because I would be typing along and notice I wasn’t typing where I should be. I would then have to delete what I was typing and move the cursor back to where I wanted and retype what I had deleted. That was happening quite often. Thanks for fixing that.

  • edited February 14 Posts: 1,705

    @Simeon @LoopSpace - managed to get the dice demo working - very impressive by direct copying from the LoopSpace gist to thee tabs I was using. Although I did occasionally hit problems with pasting into the tab, seemed like the touch/pasting was disabled. The tab giving the problems was Vec3 and was completely remarked out with --[==[ and --]==] but was not reproducible. Could these inserts cause a problem with the Codea editor?

  • dave1707dave1707 Mod
    edited February 14 Posts: 8,384

    @Simeon I’m running into a problem. If I open up a project and tap anywhere on the screen, the keyboard pops up. If I close the keyboard, I can’t bring the keyboard back up by tapping on the screen. I can bring it up only if I tap in the line number area on the left. I also can’t highlight anything in the code area to change a word. Tapping is recognized in the area between the () where I can select something.

    PS. I’m on version 196.

  • Posts: 1,705

    @dave1707 - just tested that and I can confirm I can scroll the text but can not get the cursor and keyboard back on screen. This could have been the issue that I just reported above after pasting in text - at one stage it seemed to take a long time to close the tab after tapping the X but eventually did close it.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    Thank you, looks like my fix for the input keys had unintended consequences

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon The keyboard works a lot better now. Will keep looking for other things.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Can you darken the background of the autocomplete so the words standout more against the editor. Also, is there any way that you can scroll the autocomplete area from side to side. There are times when all of the autocomplete words can’t be seen. The only way now to see all the words is to type a letter so only those autocomplete words beginning with that letter are shown.

  • Posts: 527

    @Simeon @dave1707 given the URL of a text file is there anyway to load the file into Codea? I would like to avoid having to copy my files to the ipad each time. I usually use readText(fileName) when the file is stored locally. Actually the file would be in json format.

  • dave1707dave1707 Mod
    edited February 15 Posts: 8,384

    @Simeon The example in Craft, 3D Asset Viewer need updated.

    A lot of the examples in Craft and Examples need updating. Some of them in Craft don’t respond to touch and eventually crash Codea after they’re forced closed.

    The brickout program in Examples has a problem. After several hits, the ball will hesitate for about 3/4 seconds as the sound plays when the ball hits anything.

    Same with Lua Jump. After awhile the character will pause while the sound is played.

    Craft World Generator crashes Codea.

  • Posts: 1,705

    @Simeon - @dave1707 may have covered this but the learn craft demo uses a json file and trying to find it in the documents file is impossible as when you click on the selection brackets the file display does not show the text/json files present. They are not in documents or environments. Perhaps we need a separate folder for scripts.

    Please keep the scripts and textures together for the 3D objects - perhaps we need a folder for that purpose for users to place 3D assets. In the long term I think we’ll have to get used to placing these assets in you project folders but during development a generalised folder could be useful.

    Out of interest, since I hardly ever do it, do you have to place assets in your project folder using the file app?

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon The print function isn’t working the way it should. Values separated by a comma aren’t always separated when printed. See the third and sixth print.

    function setup()
        print(1,2)
        print(11,22)
        print(111,222)
        print(1111,2222)
        print(11111,22222)
        print(111111,222222)
    end
    
  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 I've fixed the sound issue. Looking into the example projects now too.

    The print issue is not a bug but just an issue with tab characters. The comma separated print in Lua is equivalent to using the tab character \t to delimit strings. So print(1,2) is the same as print("1\t2").

    The tab character lines up its spacing at specific column counts. So when you have two strings of just the right size, the tab character can actually align them fairly close together, as it's supposed to align the strings into columns over multiple prints.

    At some point the first string "bumps" the second string up to the next column. It's just that the spacing can get quite tight before it does so. See the image showing how the columns line up.

  • dave1707dave1707 Mod
    Posts: 8,384

    @Simeon Here something I put together. The tab spacing just isn’t right. You might have to scroll the image up/down to see all of it. I added a long row of eights at the top and bottom just for alignment. The tabs/printing is lousy. If printing stops just before a tab position, then a double tab should be done to increase the space between the first and second number.

  • dave1707dave1707 Mod
    edited February 16 Posts: 8,384

    @Simeon Version 198 fixes. I’ll add things as I test them.

    I tested the sound delay on the Brickout game and the delay for sound is fixed except for the very first time that a sound is made. There is still a delay there. Adding a sound call when the program first starts fixes that.

    Ran all the projects in Examples and Crafts. Everything ran OK. Received Assets warnings on Blocky Characters, Voxel Terrain, Voxel Player, and Block Library.

    Parameter.clear with parameters was OK.

    Not sure about the other fixes. Don’t know what they’re were.

  • Posts: 1,705

    @Simeon - quick one on model loading, just added obj model which displays correctly - but the model seems to take ages to load. This is a Dropbox model and I was wondering if the model is being downloaded each time instead of loading from the local mirror of Dropbox. I synced the Dropbox folder but still a delay before presenting object image.

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @Bri_G it should always be local when you run your project (the Dropbox folder). How big is the model?

  • SimeonSimeon Admin Mod
    Posts: 5,362

    @dave1707 thank you for catching those warnings on those projects

    The other fixes all came about from investigating why many of the example projects were hanging / crashing, so thank you for pointing that out.

  • Posts: 1,705

    @Simeon - just short of 800 vertices but a number of textures, I would have thought that was OK for rapid loading. Fiddling with project to test timing.

Sign In or Register to comment.