Twine Version: 2.2.1
Story Format: SugarCube 2.27
I am starting out teaching myself Twine and to get used to using some JavaScript functions I am trying to create a really simple function that lets me check a list of flags to see if one exists.
The function in my Story Java Script is:
window.cPrompt = function (p, pList) {
var tList = State.getVar(pList);
var vResult=false;
for (let i = 0; i < tList.length; i++) {
if(tList[i]===p)
{
vResult=true;
}
}
return vResult;
};
My Twine code to test it is:
<<if cPrompt('Test Prompt',$testPrompts)==true>>
Found the prompt!!!
<<endif>>
I set up the list of prompts in StoryInit:
<<set $testPrompts=['Test Prompt']>>
When I test it I get:
“Error: <>: bad conditional expression in <> clause: Cannot read property ‘length’ of undefined”
Could anyone point out where I am going wrong please?