Read external data

Do you know what is the best way to read external data in logic nodes ?

(we have that here in Haxe https://code.haxe.org/category/beginner/using-filesystem.html … did you test it on different plateforms ? others solutions too or experiences with different OS/Filesystems ?)

1 Like

This is a biggie, also if it was possible to read data while the simulation is running in html or c++, that would be huge.

If can help you, this is the best solution I have found for the moment, thanks to @lubos and @Naxela !

2 Likes

Thank you @Didier, this is great, loading/saving data is of great use for some cases I want to use Armory in.

Finally, after several search and try, I am using the following code which is simple.

Here we try to read a json file with a node NN Json Get

image

The json file, called DT.json to read

{
“fruits”: [
{ “kiwis”: 3,
“mangues”: 4,
“pommes”: null
},
{ “panier”: true }
],
“legumes”: {
“patates”: “amandine”,
“poireaux”: false
},
“viandes”: [“poisson”,“poulet”,“boeuf”]
}

**The interesting part of the NNJsonGetNode code **

class NNJsonGetNode extends LogicNode {

.....
	override function run() {
		var value:String = inputs[1].get();
		
		var adr = "http://localhost:8040/Data/" + value;
		var http = new haxe.Http(adr);
		
		http.onData = function (data:String) {
				
			var res:{method:String,fruits:Array<Dynamic>} = haxe.Json.parse(data);
			trace("-------------------fruits-----------------------");
			for (n in res.fruits) {				
				trace(n);
			}

			var res1  = haxe.Json.parse(data);
			trace("-------------------legumes-----------------------");
			for (n in Reflect.fields(res1.legumes))
				trace(Reflect.field(res1.legumes, n));

			var res2:{method:String,viandes:Array<Dynamic>} = haxe.Json.parse(data);
			trace("------------------viandes------------------------");
			for (n in res2.viandes) {				
				trace(n);
			}
		}

		http.onError = function (error) {
		trace('error: $error');
		}

		http.request();
		
		super.run();
	}
....

tadaaa, in the console of the firefox browser, the result.

2 Likes