It looks like you're new here. If you want to get involved, click one of these buttons!
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
assetList
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)
Comments
@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.
@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.
@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.
@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.
@Simeon There give errors in the editor, but still run.
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.
@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:
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.
@Simeon - trying to abbreviate the path result in a deviation, not an error. I used:
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.
@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.
@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:
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: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.
@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.
@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
@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.
@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.
Also, the line below doesn’t cause an editor error, but crashes Codea. It doesn’t have the ) at the end of the line.
@dave1707 here's how you do it:
Basically if you take an asset path to a folder (
assets
orassets.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.
@Simeon I thought that was one of the things I tried. I tried your above example and received this.
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
worksI think these will be able to replace readProjectTab / saveProjectTab and friends. Because you could just do (when it's working!)
@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.
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
@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.
@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 insetup()
but should be a global.@Simeon - is this a recent bug, usually an error message is thrown up so we can trace the problem?
@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.
@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)
@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.
@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.
@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 ?
@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.
@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.
@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
@Bri_G you only need the file called
VecExt
from my library.@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:
Note - @LoopSpace - this is occurring in 3.1(195)
@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.
@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?
@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.
@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.
Thank you, looks like my fix for the input keys had unintended consequences
@Simeon The keyboard works a lot better now. Will keep looking for other things.
@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.
@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.
@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.
@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?
@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.
@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. Soprint(1,2)
is the same asprint("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.
@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.
@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.
@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.
@Bri_G it should always be local when you run your project (the Dropbox folder). How big is the model?
@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.
@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.