Expansions - loading sample maps behaving oddly...
-
So I'm trying to load maps into a sampler.
The basic approach is pretty simple - an inline function that takes the name of the sample map and it loads the map into a defined sampler....
.
Here's the function:inline function loadVoiceByName(voiceNumber, voiceName) { if (voiceName != "") { local testName; //look for the voice display name... for (mv in masterVoiceData) { if(voiceName == mv.VoiceDisplayName) { // found our voice if(mv.VoiceLocation != "Factory") { // its an expansion testName = "{EXP::" + "DeepHorizens" + "}"+ "DH_AirKeys"; Console.print("Constructed:" + testName ); }else{ testName = mv.VoiceMapName; } }; }; //testName = "{EXP::" + "DeepHorizens" + "}"+ "DH_Airkeys"; //<-- uncomment this line an it works! Console.print("Trying to load " + testName ); TheSamplers[voiceNumber].loadSampleMap(testName); } };
As you can see it first checks there is a value present , then looks through an array (of JSON objects) called masterVoiceData. It looks in here to find out if the name we've been sent is in fact the name of a map from an expansion...if it is it constructs the string we need (in testName) to get an expansion map to load, if its not then it just uses the passed in string value...
This loads all the "factory" content perfectly, but fails to load the expansion map every time.....
BUT.... uncomment the line at the bottom assigning exactly the same string to testName - and it works every time....
What am I doing wrong????
-
@Lindon oh n o...t-shit time again I think.....
check the spelling on the two assignments of Airkeys (or as I have it on one spot AirKeys) doh!
-
@Lindon Your nesting is killing me :)
inline function loadVoiceByName(voiceNumber, voiceName) { if (voiceName == "") return; local sampleMap; for (x in masterVoiceData) { if (voiceName != x.VoiceDisplayName) continue; if (x.VoiceLocation != "Factory") sampleMap = "{EXP::" + "DeepHorizens" + "}"+ "DH_Airkeys"; else sampleMap = x.VoiceMapName; } TheSamplers[voiceNumber].loadSampleMap(sampleMap); };
Also you might want to use the
getWildcardReference
function instead of hardcoding the expansion name. -
@d-healey oh I DONT hard code the expansion name ,I actually get it from anoth piece of the json puzzle, this was just to demonstrate the problem - which actually just demonstrated by stupidity....
Whats wrong with the nesting?
-- oh hang on I like the "continue".... dont normally use that... still...
-
@Lindon This changed how I write code and made my scripts much cleaner, easier to read and maintain
-
@d-healey cool I will take a look, here's wjhat a correctly working version of this look like:
inline function loadVoiceByName(voiceNumber, voiceName) { if (voiceName != "") { TheSamplers[voiceNumber].loadSampleMap(voiceName); } };
-
@d-healey oh hang on I've watched that video before _ I must admit I'm a big user of
if(!value) return;
these days...as a result.