Regarding assets

@sim @john - I was very used to the older way of managing assets and had a few ways of handling them. My main aim with assets was to keep those I used in project developments in folders within the Codea root labelled as project.assets. This approach meant that I could use assets from different folders in new projects thus saving Codea memory space.

I am happy with the new approach with an asset option from the editor drop-down list, but recently crashed Codea several times by getting into old habits in moving and naming folders in the Codea root. Could you explain the do’s and don’ts for the new system.

Also, this may be a big ask, but would it be possible to have an asset loading system which used the iOS selection tag so that you can choose multiple assets to add to your project list for use/importing into your Codea project. Also, could you import the asset name provided in the list so that you don’t have to name every asset when importing - leaving the asset name in an edited field if you do wish to change it.

Finally, could you explain what happens when you export a project as a zip, ideally it would include all the relevant assets with corrected paths in the exported project.

Edit: on the last point, thinking about it, it would probably be better to include a button/selection widget to include or not include the assets and correcting paths.

@jfperusse - nice to see the latest version with require available. Thought it would help me with the topic of this thread but I have an issue with it :vulcan_salute:

Using the asset path approach you only seem to see assets in the root and assets in an existing project. As described earlier I tend to use assets in a folder which used to be accessible directly from code. Using folders like jigsaw or jigsaw.assets enabled me to use assets within them globally. The latter was also very visible if you added the icon.png and the info.list that were present in Codea project folders.

Any chance you could make folders like these visible by require ?

Edit: @jfperusse - after a little fiddling found that the path works but doesn’t fire up any sprite images for my target folder, but it does show images from a project loaded one by one with naming using the assets facility in Codea. What do you think of my comments above?

Hi @Bri_G. I am not sure I understand your usage exactly. The new “require(AssetKey)” feature is only for importing lua files in the project, not assets like textures, etc.

To organize common assets (or even lua files you would want to require), you can create external folders from the assets library either on your device or on the cloud, and these will be accessible to all your projects.

If this doesn’t answer your needs, could you please give us more details as to what you are trying to achieve that does not work?

Thank you!

1 Like

@jfperusse - thanks for the reply. I think what you are saying is that require will operate as in Love2D and is similar to the dependencies in Codea. I’m not sure if there any other features to require in Codea.

On playing with my image assets I find a visual list of images is supplied, with the image name but looks like it requires you to give it a name as there is a field opened for that purpose which feels superfluous to my needs. I just need to select the images I need.

So I proposed listing the images required with a selection button (like iOS selectors) so a simple tap will identify the image assets required.

What I envisaged with that was Codea could then produce a text list of the assets required which could be added to the Codea project list with a name definition or as a field in a table.

P.s. does Codea require pre-load other code as Love2D does.

Also is there any way require could be used to ‘chain’ another program from a parent so you could effectively run multiple projects from a menu?

@Bri_G I’ll try to answer as best as I can. require() is indeed the same as dependencies (or an “import/include” in other languages), but also works in Carbide, making it the “new” way to import (or pre-load) code dependencies in a project. If you require a specific lua asset, it will be imported globally. If you require a codea project, it will import all its lua files except Main.lua. Since you cannot have multiple definitions of the same functions globally (e.g. setup, draw, etc.), you cannot use this directly to import multiple projects. That being said, I think you could technically backup your setup/draw functions, require a project, then manually require its Main.lua file and call setup() to run that other project, but I have not tested this.

For external folders, if your files are already there (e.g. using the Files app on iOS, or dropping files in iCloud from another device), then they keep their filename as the name of the asset, so I am not sure what you are referring to about the field which I don’t see in this use-case.

What would the text list of assets required be used for, considering the asset selection menu (e.g. taping on the sprite() parenthesis) allows you to select from any project’s asset, document or external folder?

@jfperusse - thanks for the feedback and I’m now up to speed on the require issue.

On the selection option though I think I do have a point. I have attached two images that show what I mean.

if you tap on the assets menu link (top right in the editor) you can select a folder containing assets which are displayed with their name. Tap on any one and it displays in a new window with a blank field to enter a name. So you have to enter a name before proceeding. Not an issue for the odd item but if you have many assets you need to add then it gets to be a bit of a pain.

Is it possible to import and display the name, in an editable field, so you can edit or accept the existing name instead of requiring the addition of the name.

I presume it’s done in this way so you can change the name as the asset will be to the current development projects Codea folder, but I don’t see the need for that as during development you would use the source asset folder and hopefully, when you export the project, the assets would be added to the project zip and the relevant code paths adjusted (as in my original suggestion for this thread).

An easy way to do that would be to provide a variable like

path = “asset.documents.folder”

In your setup() and change that when exporting your project.


There are a few separate things here:

  1. Importing a single asset. In this case you navigate into an existing folder or asset pack, and press the + button. From there you can choose to import a single file or photo. Once you do, you are prompted to enter a name — @Bri_G this is where we could take on your suggestion to use the existing file name, and even allow multi-selection so you could select multiple files and have them come through with their original name

  2. Creating a folder reference. This will “link” the folder to Codea, similar to how we used to link Dropbox folders. Any assets in this folder will become available via the asset.ExternalFolderName.file syntax
    image

@sim - thanks for the reply. If you do decide to follow up on my suggestion that would make setting up new projects with existing assets slicker and less frustrating.

Thanks again.