Going bonkers with parseInt, would appreciate assistance. I've greatly abbreviated the script below while trying to retain it well enough to see what's going on. The challenge I'm having is that I've added a variable "vModifier" as the last bit of the global java. Everywhere it is called, I see the correct value, and on the "Ask" page the math works with the random value and vModifier being added together as intended.
Where I'm running into trouble is that I would like to update the vModifier on the Allow, Ruin, and No pages by a static amount (i.e vModifier + 3) and no matter how I try, the math doesn't work (I've tried many different parseInts, along with static numbers, variabilized increments, etc). I'd also want that value to be persisent throughout the session (resetting only on a new session or restart).
So if anyone could help me work out how to have the value of vModifier be 0 on startup, and then add a number to it (that then remains as an offset) when it hits any of the Allow, Ruin, or No pages, I'd really appreciate it.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<Tease>
<Title>At thier whim v11</Title>
<Author id="">
<Name>""</Name>
</Author>
<MediaDirectory>At thier whim</MediaDirectory>
<Settings>
<AutoSetPageWhenSeen>false</AutoSetPageWhenSeen>
<ForceStartPage>true</ForceStartPage>
</Settings>
<GlobalJavascript>
<![CDATA[
//Difficulty settings: Very Easy = 0, Easy = 1, Medium = 2, Hard = 3, Very Hard = 4, Insane = 5, TESTING = 6
var arrayModel = [
{ Name: "TEST", sortOrder: 999, Sets: [
{Difficulty: 6, Path: "Test\\Test-1" },
{Difficulty: 6, Path: "Test\\Test-2" },
{Difficulty: 6, Path: "Test\\Test-3" },
{Difficulty: 6, Path: "Test\\Test-4" },
{Difficulty: 6, Path: "Test\\Test-5" },
{Difficulty: 6, Path: "Test\\Test-6" }]},
];
//Time is in seconds
var arrayDifficulty = [
{ Level: "Very Easy", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "Easy", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "Medium", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "Hard", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "Very Hard", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "Insane", DelayMin: 0, DelayMax: 0, AllowChance: 0, RuinChance: 0},
{ Level: "TEST", DelayMin: 3, DelayMax: 3, AllowChance: 33, RuinChance: 33},
];
var arrayAllow = [
"yes",
];
var arrayRuin = [
"oops",
];
var arrayDeny = [
"no",
];
var vModifier = 0; //Modifier adds to the "Ask" roll, slowly increasing the chance of success with each model
]]>
</GlobalJavascript>
<Pages>
<Page id="start">
<Text>Who'd you like to see?</Text>
<Image id="Welcome.jpg" />
<javascript>
<![CDATA[
function pageLoad() {
var i = 0;
var vSelected = parseInt(scriptVars.get("vSelected"),10);
jscriptLog("vSelected = " + vSelected);
if ( isNaN(vSelected) || vSelected == undefined ) {
vSelected = 0;
scriptVars.put("vSelected", vSelected);
jscriptLog("vSelected initialized to " + vSelected);
}
for (i=0; i < arrayModel.length; i++) {
var vName = arrayModel[i].Name;
var vSort = arrayModel[i].sortOrder.toString(); //sortOrder parameter needs to be a string
overRide.addButton("Confirm", vName, "", "", "setModel(" + i +")", "", "", vSort, false, "");
}
var i = parseInt(scriptVars.get("vSelected"),10);
overRide.setHtml("Who'd you like to see this time? <br/>Last time you visited " + arrayModel[vSelected].Name + "<br/><br/>Current modifier value = " + vModifier);
overRide.addButton("Confirm", "Revist Last", "", "", "setModel(" + i +")", "", "", "", false, "");
overRide.addButton("Confirm", "You Choose", "", "", "setRandomModel()", "", "");
}
function setModel(i)
{
scriptVars.put("vSelected", i);
// And randomly select a set to use and save this for other pages to access
var vSet = Math.floor(Math.random()*arrayModel[i].Sets.length);
scriptVars.put("vSet", vSet);
}
function setRandomModel()
{
var i = Math.floor(Math.random()*arrayModel.length);
scriptVars.put("vSelected", i);
var vSet = Math.floor(Math.random()*arrayModel[i].Sets.length);
scriptVars.put("vSet", vSet);
}
]]>
</javascript>
</Page>
<Page id="Confirm">
<Text>Seeing this means something went wrong on the page - Confirm</Text>
<Image id="test.jpg" />
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vDiff = arrayModel[i].Sets[vSet].Difficulty;
var vLvl = arrayDifficulty[vDiff].Level;
var text = arrayModel[i].Name + ":<br/>Are you ready to begin?<br/><br/>";
overRide.setHtml(text);
overRide.image = vPath + "/ready.jpg";
}
]]>
</javascript>
<Button target="start">Someone Else</Button>
<Button target="ChangeSet">Different Set</Button>
<Button target="Wait">Let's Begin</Button>
</Page>
<Page id="ChangeSet">
<Text>Seeing this means something went wrong on the page - ChangeSet</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
scriptVars.put("vSelected", i);
var vSet = Math.floor(Math.random()*arrayModel[i].Sets.length);
scriptVars.put("vSet", vSet);
}
]]>
</javascript>
<Delay seconds="0" target="Confirm" style="hidden"/>
</Page>
<Page id="Retry">
<Text>Seeing this means something went wrong on the page - ChangeSet</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
scriptVars.put("vSelected", i);
var vSet = Math.floor(Math.random()*arrayModel[i].Sets.length);
scriptVars.put("vSet", vSet);
var vPath = arrayModel[i].Sets[vSet].Path;
var vDiff = arrayModel[i].Sets[vSet].Difficulty;
var vLvl = arrayDifficulty[vDiff].Level;
}
]]>
</javascript>
<Delay seconds="0" target="Wait" style="hidden"/>
</Page>
<Page id="Wait">
<Text>Seeing this means something went wrong on the page - Wait</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vDiff = arrayModel[i].Sets[vSet].Difficulty;
var vMinDel = arrayDifficulty[vDiff].DelayMin;
var vMaxDel = arrayDifficulty[vDiff].DelayMax;
var vDelay = Math.floor(Math.random() * (vMaxDel - vMinDel + 1)) + vMinDel;
overRide.setHtml(arrayModel[i].Name + ": Waiting...");
overRide.image = vPath + "/Wait/*.jpg";
overRide.setDelay("Ask", vDelay, "", "hidden", "", "", "");
}
]]>
</javascript>
<!-- <Button target="Ask">proceed-test</Button> -->
</Page>
<Page id="Ask">
<Text>Seeing this means something went wrong on the page - Ask</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vDiff = arrayModel[i].Sets[vSet].Difficulty;
var vAllowCase = 100 - parseInt(arrayDifficulty[vDiff].AllowChance,10);
var vRuinCase = vAllowCase - parseInt(arrayDifficulty[vDiff].RuinChance,10);
var rand = guide.getRandom("(1..100)");
var roll = rand + vModifier;
switch (true)
{
case roll > vAllowCase:
overRide.addButton("Allow", "Please...", "", "", "", "", "");
break;
case roll > vRuinCase:
overRide.addButton("Ruin", "Please...", "", "", "", "", "");
break;
default:
overRide.addButton("No", "Please...", "", "", "", "", "");
}
overRide.setHtml("Ask nicely" + " " + rand + "-" + vModifier + "-" + roll);
overRide.image = vPath + "/Ask/*.jpg";
}
]]>
</javascript>
</Page>
<Page id="Allow">
<Text>Seeing this means something went wrong on the page - Allow</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vResponse = arrayModel[i].Name + ": " + arrayAllow[Math.floor(Math.random()*arrayAllow.length)];
overRide.setHtml(vResponse + " - " + vModifier);
overRide.image = vPath + "/Yes/*.jpg";
}
]]>
</javascript>
<Button target="start">Someone else?</Button>
<Button target="Retry">Try Again?</Button>
</Page>
<Page id="Ruin">
<Text>Seeing this means something went wrong on the page - Ruin</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vResponse = arrayModel[i].Name + ": " + arrayRuin[Math.floor(Math.random()*arrayRuin.length)];
overRide.setHtml(vResponse + " - " + vModifier);
overRide.image = vPath + "/No/*.jpg";
}
]]>
</javascript>
<Button target="start">Someone else?</Button>
<Button target="Retry">Try Again?</Button>
</Page>
<Page id="No">
<Text>Seeing this means something went wrong on the page - No</Text>
<javascript>
<![CDATA[
function pageLoad() {
var i = parseInt(scriptVars.get("vSelected"),10);
var vSet = parseInt(scriptVars.get("vSet"),10);
var vPath = arrayModel[i].Sets[vSet].Path;
var vResponse = arrayModel[i].Name + ": " + arrayDeny[Math.floor(Math.random()*arrayDeny.length)];
overRide.setHtml(vResponse + " - " + vModifier);
overRide.image = vPath + "/No/*.jpg";
}
]]>
</javascript>
<Button target="start">Someone else?</Button>
<Button target="Retry">Try Again?</Button>
</Page>
</Pages>
</Tease>