As I understand, you want to keep all of the element execution purely in script. If that so, I suggest just keep the whole element which can be done without script the way they are. Until now, I don't know if there is a way to execute the element action in script, AFAIK Automagic doesn't have the function to do it. There is a global lock that occur when a script, expression or control UI is running. Even if there is a way to do it, you will suffer from a lot of unnecessary delay caused by the global lock. So better split them as the way they are.
But if you mean to control the sound file path per level, and create some sound based on the level; you can do it using map dan some lookup logic similar to vlookup in excel. Example, you splitted the level per 10% and give 10 different sounds for each stage. You will need a map to store all the possible path and loop the battery_level to it. You can get the battery_level from the trigger or condition battery level.
Code: Select all
sounddb = newMapFromValues(
0, "/sdcard/Automagic/sound/alpha.mp3",
10, "/sdcard/Automagic/sound/bravo.mp3",
20, "/sdcard/Automagic/sound/charlie.mp3",
30, "/sdcard/Automagic/sound/delta.mp3",
40, "/sdcard/Automagic/sound/echo.mp3",
50, "/sdcard/Automagic/sound/foxtrot.mp3",
60, "/sdcard/Automagic/sound/golf.mp3",
70, "/sdcard/Automagic/sound/hotel.mp3",
80, "/sdcard/Automagic/sound/india.mp3",
90, "/sdcard/Automagic/sound/kilo.mp3" );
for(i in getMapKeys(sounddb))
if(battery_level > i) path = sounddb[i];
Change each level sound file path to the real sound path those you have prepared. The script will loop check the battery_level, if it is higher than one of the sounddb's key, then it will assign {path} to the sound path. After passing the script, the sound {path} will be mapped to the correct sound path according to the level. Example if your current battery_level is 42, then it will get "/sdcard/Automagic/sound/echo.mp3". You can then use {path} in the action sound, to produce the sound.
If this is not what you want, you have to be more specific. Sorry, but my German is not that good yet, I still relied on Google Translate.