Forum Discussion
"Superuser" Feature
This is the code I use
//Opens a Storyline variable debugger window
//Add this JavaScript to some Storyline trigger (ex: when user presses F9 in the slide master)
"use strict";
var pl = GetPlayer();
var debugWin = window.open(undefined, "debug", "width=600,height=800,toolbar=no,location=no");
var debugDoc = debugWin.document;
debugDoc.body.innerHTML = "";
debugDoc.title = "Storyline Debugger";
var refreshButton = debugDoc.createElement("INPUT");
refreshButton.value = "Refresh";
refreshButton.type = "button";
refreshButton.addEventListener("click", refreshVars);
debugDoc.body.appendChild(refreshButton);
var tableElem = debugDoc.createElement("TABLE");
debugDoc.body.appendChild(tableElem);
getStorylineUserVariables(function (slVars) {
slVars.sort(function(x, y){return x.name > y.name;});
for (var a = 0; a < slVars.length; a++) {
var v = slVars[a];
var trElem = debugDoc.createElement("TR");
if (a % 2 == 1) trElem.style.backgroundColor = "#dddddd";
var tdElem = debugDoc.createElement("TD");
tdElem.innerHTML = v.name;
tdElem.style.padding = "10px 2px";
trElem.appendChild(tdElem);
var inputElem = debugDoc.createElement("INPUT");
inputElem.storylineVarName = v.name;
if (v.type == "number") {
inputElem.type = "number";
inputElem.step = undefined;
inputElem.value = pl.GetVar(v.name);
} else if (v.type == "boolean") {
inputElem.type = "checkbox";
inputElem.checked = pl.GetVar(v.name);
} else {
inputElem.type = "text";
inputElem.value = pl.GetVar(v.name);
}
tdElem = debugDoc.createElement("TD");
tdElem.appendChild(inputElem);
trElem.appendChild(tdElem);
tableElem.appendChild(trElem);
}
} );
tableElem.addEventListener("change", function (e) {
var inputElem = e.target;
var slVarName = inputElem.storylineVarName;
var newVal = "";
if (inputElem.getAttribute("type") == "checkbox") {
newVal = inputElem.checked;
} else {
newVal = inputElem.value;
}
pl.SetVar(slVarName, newVal);
} );
function refreshVars () {
var inputs = tableElem.querySelectorAll("input");
for (var a = 0; a < inputs.length; a++) {
var elem = inputs[a];
var val = pl.GetVar(elem.storylineVarName);
if (elem.type == "checkbox") {
elem.checked = val;
} else {
elem.value = val;
}
}
}
function getStorylineUserVariables(callback) {
//Overide Storyline's globalProvideData function temporarily
var origGlobalProvideData = window.globalProvideData;
var scriptElem = document.createElement("SCRIPT");
scriptElem.src = "html5/data/js/data.js";
window.globalProvideData = function (foo, data) {
var dataObj = JSON.parse(data);
var variableList = [];
for (var a = 0; a < dataObj.variables.length; a++) {
var varObj = {name: dataObj.variables[a].name, type: dataObj.variables[a].type, defaultValue: dataObj.variables[a].value};
if (varObj.name.match(/^[0-9a-zA-Z]{11}_RetryModeInteractionIncompleteOnLoad$/) == null &&
varObj.name.match(/^LastSlideViewed_[0-9a-zA-Z]{11}$/) == null &&
varObj.name.match(/^PrintPromptUsername_[0-9a-zA-Z]{11}$/) == null &&
varObj.name.match(/^PrintPromptWindowQuizVar_[0-9a-zA-Z]{11}$/) == null){
variableList.push(varObj);
}
}
document.body.removeChild(scriptElem);
window.globalProvideData = origGlobalProvideData;
callback(variableList);
}
document.body.appendChild(scriptElem);
}
Thank you for that.