Forum Discussion
Changing state directly from JavaScript?
I'm back finding that I'd really like to do this again. I'd love to have something like:
player.SetState("nameofobject", "state name");
Allthough i do have some hickups in showing the proper state...
this code hides all states of a given element.let baseElement = document.querySelector("[data-acc-text='myElement']");
let parent = baseElement.parentNode;
let allDIVS = parent.getElementsByTagName("div");
hideAllStates();
function hideAllStates(){
for (let i = 0; i < allDIVS.length; i++) {
let dataModelID = allDIVS[i].getAttribute('data-model-id');
if(dataModelID != null ){
allDIVS[i].classList.remove('shown');
allDIVS[i].classList.add('hidden');
}
}
}
Then you can target a state and show that.let baseElement = document.querySelector("[data-acc-text='myElement']");
let parent = baseElement.parentNode;
let allDIVS = parent.getElementsByTagName("div");
showState();
function showState(){
for (let i = 0; i < allDIVS.length; i++) {
let dataModelID = allDIVS[i].getAttribute('data-model-id');
if(dataModelID != null ){
allDIVS[3].classList.remove('hidden');
allDIVS[3].classList.add('shown');
}
}
}
As said this only works when duplicating states. If you make them any other way, Storyline makes up other HTML and this wont work. Also there still are some things to fix in the showing part... but basically it works.