February 2, 2018 at 9:28 pm #13426
I’d like to detect if an asset if present in order to send an error message. But I suppose filesystem functions are not valid for that.
Is there another way than checking if the Loadxxx() function returns null?February 3, 2018 at 1:27 am #13432
I do the following in Diddy2:Monkey1234567Local image:Image = Image.Load(path)If Not imagePrint("Error: Can not load image: " + path)App.Terminate()EndFebruary 3, 2018 at 7:06 am #13434
Quick question, is it possibile to use GetFileType(path) to known if that file exists or not? It should be faster
Not tested, just thinking…
edit – tested using RenderToImage exampleMonkey1234567Local ft:=GetFileType(AppDir()+"/assets/spaceship.png")Select ftCase FileType.File Print "File"Case FileType.Directory Print "Folder"End Select
Of course it would be better creating a ‘CheckForFile’ functionFebruary 3, 2018 at 7:31 am #13435
AppDir() is not cross platform and will not always return the folder you think it will.
Windows and mac’s have different app structureFebruary 3, 2018 at 7:57 am #13437
Ahhh…. Good to know.
But at this point what’s the sense of having a command like AppDir (and I suppose AppPath) that returns ‘not sure’ results?
will not always return the folder you think it will
What does it means?
That on my computer and your computer (supposing both running Windows10) there are different returned path?
I suppose internally Image.Load() will ‘found’ the correct path in some way (and surely is in the /assets folder of the final application)… so replicating this should be the correct solution I think.
Question: when MX2 compiles/build everything it does *just* copy any file/folder defined with #Import and (looking at the source code) it seems to ‘add’ to product.ASSET_FILES any single ‘resources’ (=Path/file).
I don’t know if that ‘collection’ is ‘public’ to the application (so it would be easy to check if something is missing or not).February 3, 2018 at 10:56 pm #13452
What about trying AssetDir?Monkey12345std:std.filesystem.AssetsDirFunction AssetsDir:String( )Gets the filesystem directory of the app's assets directory.Note that only the desktop and web targets have an assets directory. Other targets will return an empty string.February 4, 2018 at 12:08 am #13457
I looks like I’ll have to check for Null result.
ThxFebruary 4, 2018 at 12:33 am #13458
Checking for null kinda works, but is not ideal.
Sometimes you get null when there’s a file format problem, which is common when dealing with various 3d formats that are not entirely standard, like FBX and its multiple iterations over the years. In cases like that, it can take longer than necessary to figure out where the problem is (file name wrong? format error? typo? did I forget to put it in the right folder? etc.).
Ideally, attempting to import a non-existent asset should cause a specific errors, at least on Debug mode.
Cheers.February 4, 2018 at 1:28 am #13459
AssetsDir()+path etc will work for most targets, it’s only android that causes problems as assets are stored in a zip file on android. On all other targets, assets are just files in the filesystem, so GetFileType etc will work.
What will work safely is opening the asset as a stream, eg:Monkey12345678910111213Function AssetExists:Bool( path:String )If Not path.StartsWith( "asset::" ) path="asset::"+pathLocal stream:=Stream.Open( path )If Not stream Return Falsestream.Close()Return TrueEnd
(untested).February 4, 2018 at 8:38 am #13461
On all other targets, assets are just files in the filesystem, so GetFileType etc will work.
Looking at the source code in AssetsDir() seems that
1. documentation should be updated as target IOS seems to ‘return’ the correct path. So the problem is only for ANDROID
2. on ANDROID target it would be nice (as the function returns a string) to just put in the debug a ‘warning’ about the use of that function.
in any case I think that even ANDROID_TARGET should return a string about the internal ‘assets’ folder. Then is up to the developer – if wanted – use that path to access/open the .zip structure to read/check the asset.
You must be logged in to reply to this topic.