Expansion - Access AdditionalSourcecode file
-
@d-healey coming back to this finally - it's working as you explained, and thanks for the project. I'm not massively familiar with using jsons - how do I get the value of "Value" into HISE script so I can assign it to something?
-
@DanH From the JSON file you'll just get a standard Javascript object inside your script, so you can use it like any other object. If you want to view the contents you can use the script watch table or just
Console.print(trace(objName));
-
@d-healey that's what I hoped would happen
So if the JSON just contains:
{ "NumberData" : "10" }
then in my script I should just be able to go:
reg = MyNewNumber; MyNewNumber = NumberData;
Or no?!
-
Off the top of my head...
var myObj = Engine.loadFromJSON("somefile"); Console.print(myObj.NumberData);
-
@Lindon Thanks! :)
-
-
@DanH You can use
if (!isDefined(myObj))
to check if it's there or not. -
@d-healey ok trying. I'm not sure where to put "reg mrdata = cx.loadDataFile("maxrandomdata.json");" as if it goes before the if statement then I get an error, and if it goes in the else statement it gets ignored... I was trying:
if (cx.loadDataFile("maxrandomdata.json") == undefined)
before you wrote that... Where I'm at now is below:
if (!isDefined(mrdata)) { maxrandom = 35; } else { reg mrdata = cx.loadDataFile("maxrandomdata.json"); maxrandom = mrdata.maxrandomnumber; }
-
@DanH Make a minimal snippet, we need to see some context.
-
var myObj = Engine.loadFromJSON("somefile"); if (myObj) { Console.print(myObj.NumberData); }else{ myObj = {NumberData : 444}; }
-
@d-healey there's some general expansion stuff at the top, head down to the end for this bit
HiseSnippet 1477.3ocsW8uaaaCDVJIZXVaCaEaO.D9elLPhqy5O1.JJVhcbZLVicPbZ2JxJJnonrYiDofDcsMJ567dC1tSRVR1xIKyXUHHvj7tie22c73wKhTLdbrJxvr1UKB4Fles0vER8jNSnBoQuSLL+Vq.57HpzUEn4wZi1KBowwbWCSyceAJjYs8LR99qesM0mJY7hoLLdsRv3uTDHzEydwQ+lv2+TpK+JQPIoe7Q8XJYGkuZJ.ncsZYDRY2PGy6SQw1wxv7K55JzpngZJ.FCy8ZqbWLbhZlLU9WKhEi743fCMFBFJc5SU9tHhwYM5LQ36dwRGO1.rxEEzvtozvOXctvUjOeAc7cIKPJznLeX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oR026qz7Av4Er5sMr95K44sw0xp7jzzxFVF6DM5tTzIkSKe2AJHzd1p87Yc687UtkTVZg0RBpj8jB8fPt71ZT0HqZL1eXFp.Q0IcG9cYcG1AKz0VM2P.sA98VUJ.aj.+Rcnejwq5gYRKMJX+htFf4Ng+AnC9zVPqYcBO9FsJLQ1rqCflx+OBg44a+QdGsHe.gcDbe.vfl33jNHLLcrxZJxt8fKeAo8wCGZe9f9CNX3a5e0Y1869pKGb1fK6CupnRGyPu5J2o9T8pMviuZIaA.Uqz0L1mHfU8hxup4+st5uuP7AVWfM2rYLtyFvHD69bfwr2B8MVc87fHWA.2y5z+3yyCeLtTMUC2bcNEZAByEfRBCgmCx3vtKkPUDL+XG7rP53V3XjAFxktIC9a3KawCwwlYKd3xEMBnrH06XomfvWa8kIy.XRl7PyZVmiiIGt7vhkUqlsLBfG98NFCc+CfimaVmeZKz4QagNOdKz4IagNOcKz4m2Bc9k6TG7M2GOUqBRON.SbQ2jhVllckTHyJIKz3e.x75wPB
Thank you!
-
As far as I'm aware this is no longer required, but the docs haven't been updated.
expHandler.setAllowedExpansionTypes([expHandler.FileBased, expHandler.Intermediate, expHandler.Encrypted]);
The only variable you should ever be declaring inside inline functions is
local
.
https://docs.hise.audio/scripting/scripting-in-hise/hise-script-coding-standards.html#variablesDon't do this:
if (cx.loadDataFile("NewNumber.json") == undefined)
It's inefficient because you'll have to read from disk more than once. Instead load it once and store it in a local variable, or if you are going to be using the data in other parts of your script you could use a reg variable in your on init callback or at the top of your namespace.
-
@d-healey said in Expansion - Access AdditionalSourcecode file:
Don't do this:
if (cx.loadDataFile("NewNumber.json") == undefined)
It's inefficient because you'll have to read from disk more than once. Instead load it once and store it in a local variable, or if you are going to be using the data in other parts of your script you could use a reg variable in your on init callback or at the top of your namespace.
Thanks :)
But if the file doesn't exist then I get the error which prevents the rest of the script from running. That's the wall that I'm hitting. Unless I misunderstand?
To put this into context I've supplied an Expansion which doesn't have this file inside and I'd rather not update all the users if there's a way to get around it!
I'm using this elsewhere which works fine (no errors) - was hoping the same would apply in my expansion callback:
if(Engine.loadFromJSON("..//AnaData.js") == undefined)
-
@DanH as I said:
var myObj = Engine.loadFromJSON("somefile"); if (myObj) { Console.print(myObj.NumberData); }else{ myObj = {NumberData : 444}; }
-
@Lindon Thanks, but that will look in the appData folder for the file, whereas I'm in an active expansion.... Or am I getting confused?
-
@DanH You're not confused, but you could just take Lindon's code and adjust it to load from an expansion (and don't use
var
) :)local e = expHandler.getCurrentExpansion(); local data = e.loadDAtaFile("NewNumber.json"); if (isDefined(data)) { // Do the thing } else { // Do the other thing }
-
@DanH my takeaway from this is that Engine.loadFromJSON can handle a file not being there but currentexpansion.loadDataFile cannot, and produces an error...
-
@d-healey yup, but I can't get past .loadDataFile if there's no data file
HISE doesn't seem to like it (unlike Engine.loadFromJSON)
-
@DanH Which line gives the error and what is the error?
-
@d-healey
Error:Interface:! Cant find data file {EXP::TEST}NewNumber.json
Line:
local data = e.loadDAtaFile("NewNumber.json");