About Monkey 2 › Forums › Monkey 2 Development › #Import "assets/something" why import lines for this ?
Tagged: asset
This topic contains 7 replies, has 3 voices, and was last updated by 
 Richard Betson
 2 years, 6 months ago.
- 
		AuthorPosts
 - 
		
			
				
August 5, 2016 at 8:31 pm #2808
Why do we need to import all the assets first.
> are they loaded at that point in memory (I guess not) ?
#Import “assets/test.png”
#Import “assets/test.json”But then later we have to write again the ‘path’
Local obj:=JsonObject.Load(‘asset::test.json’)Why is this ?
Why not just one (path) line like this (not working)
Local obj:=JsonObject.Load(‘assets/test.json’)Or a mix like this
#Import “assets/*.json”
or
#Import “assets/*”If some game have more then 100 assets :S :S
What is the idea behind this ?
August 5, 2016 at 8:58 pm #2809Local obj:=JsonObject.Load(‘assets/test.json’)
This loads directly from the filesystem, and will work if you’re in the right current directory, eg:
ChangeDir( ExtractDir( AssetsDir() ) ) ‘changedir to parent dir of assets dir.
Local obj:=JsonObject.Load( ‘assets/test.json’ )
But note that if you’re trying to write something that runs everywhere, assets may not even be stored in the filesystem (eg: on android they’re stored in a zip), so it’s safest to use ‘asset::’
#Import “assets/*”
This will be in the next release.
August 6, 2016 at 11:28 am #2826Oke.
I din’t know about the zipfile construction, I will use the asset:: thing.
#Import “assets/*” would be cool and easy.
My json loader will load all the assets (something like atlas)I had this situation because
a.monkey2
#Import “src/JSONLoader”
Field json:JSONLoader = New JSONLoader()
json.loadScene(“assets/scene1.json”)b.monkey2
Method loadScene(_inpJSONFile:String)
Local obj:=JsonObject.Load( _inpJSONFile ) ‘ but that don’t not work nowThis is working
a.monkey2
#Import “src/JSONLoader”
#Import “assets/scene1.json”
Field json:JSONLoader = New JSONLoader()
json.loadScene(“assets::scene1.json”)b.monkey2
Method loadScene(_inpJSONFile:String)
Local obj:=JsonObject.Load( _inpJSONFile )September 29, 2016 at 7:25 pm #4157What does the jsonvalue.save() do ?
But note that if you’re trying to write something that runs everywhere, assets may not even be stored in the filesystem (eg: on android they’re stored in a zip), so it’s safest to use ‘asset::’
I need to store save files and other files on all devices (future proof) so first I thought this is the way:
Monkey1234567891011121314151617181920212223242526272829#Import "<std>"#Import "assets/"Using std..Function Main()' reading using the asset::syntax' =====================================================Local obj:=JsonObject.Load("asset::data-world1.json")If Not objPrint "No json data filea"ReturnEndPrint obj.ToJson()' =====================================================' ingame 'editor' or save file that is write json data' =====================================================Local json_data:JsonObject = New JsonObject()json_data["test"] = New JsonString("bla")'Print json_data.ToJson()json_data.Save("asset::data-world1.json") ' don't work' json_data.Save("assets/data-world1.json") ' don't work' f_data.WriteString(json_data.ToJson()) ' probably work, but is it needed ?' =====================================================' don't write to that asset , and no errorEndIn other words, what is the best path to save files so it works on all clients devices/desktop
In the example above I’m trying to overwrite the official data-world1.json file with new data.
What is the path to do that for all devices/desktopSeptember 29, 2016 at 8:30 pm #4161In other words, what is the best path to save files so it works on all clients devices/desktop
These need to be added…
September 30, 2016 at 4:38 am #4162These are some of the issues I encountered and posted about before version 1.0.0. As of now I am loading all of my assets using Image.Load() or LoadString(). The asset count for my project is well beyond using #import asset and most of the assets must be loaded at runtime. An example of this is assets for a game map or skin images or text based configuration files all of which are dynamic. It really is an issue of scope and scale as larger more enterprising or specialized projects just may not work well with the #Import asset model.
I did like the way MX1 handle this with use of a path to the data folder ala. monkey://data/.
September 30, 2016 at 5:36 am #4165I did like the way MX1 handle this with use of a path to the data folder ala. monkey://data/.
The mx2 system works pretty much the same way. Any asset files you #import are copied into the apps ‘data’ folder (just like mx1’s blah.data dir) and using “asset::blah…” as a file path will load an asset at runtime.
You can replicate mx1 exactly-ish by using #Import “myapp.data/” or whatever at the top of your code. The trailing ‘/’ means to copy the whole dir. You can then use “asset::” to load these assets at runtime.
September 30, 2016 at 6:10 am #4168I’ll give that a try. Thanks.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.