I found a script written by the user bawpie like two and a half years ago for making branching dialogue in sugar cane, so I loaded into my story and I can't get it to work. First I was getting an unterminated string error, which I researched and discovered might be due to line breaks. So I went in and got rid of those, and now I'm getting a missing ) after condition error. I have looked through this code, but it's pretty complex and not being super well-versed in Javascript, I can't seem to find the error. Please help.
(function () { version.extensions['dialoguemacro'] = {major: 1, minor: 0, revision: 0};
macros['append'] = macros['answer'] = macros['question'] = macros['choiceblock'] ={handler: function(place, macroName, params, parser) { var openTag = macroName, closeTag = "end" + macroName, start = parser.source.indexOf(">>", parser.matchStart) + 2, end = -1, tagBegin = start, tagEnd = start, opened = 1;
while ((tagBegin = parser.source.indexOf("<<", tagEnd)) !== -1 && (tagEnd = parser.source.indexOf(">>", tagBegin)) !== -1) { var tagName = parser.source.slice(tagBegin + 2, tagEnd), tagDelim = tagName.search(/\s/);
if (tagDelim !== -1) {
tagName = tagName.slice(0, tagDelim);
}
tagEnd += 2; switch (tagName)
{ case closeTag: opened--; break; case openTag: opened++; break; } if (opened === 0) { end = tagBegin; break; } } if (end !== -1)
{ parser.nextMatch = tagEnd;
id = params[0];
contents = parser.source.slice(start, end);
switch (macroName) { case "choiceblock": switch(id){ case "1": new Wikifier(place, '<<loadJS fakechoice1.js>> <div class="inlinechoice-' + id + '" id= "' + id + '"><br>' + contents + '</div>' + '<div id="dialogue_container"> </div>');
break; default: new Wikifier(place, '<div class="inlinechoice-' + id + '" id="' + id + '"><br>' + contents + '</div>' + '<div id="dialogue_container"> </div>');
} break; case "question": if (params.length - 1 % 2 == 1) {throwError(place, "<<" + macroName + ">>: odd number of parameters given"); return; } el = document.createElement('a'); el.className = 'internalLink';
el.href = "javascript:void(0)"; el.innerHTML = ('<a class="question" id="' + id + '">' + contents + '</a>');
el.onclick = function(){
for (var index = 0;index < params.length; index += 2) {var s;
if (isNaN(params[index+2])) {
s = "state.history[0].variables." + params[index+1] + " = '" + params[index+2] + "'";} else {s = "state.history[0].variables." + params[index+1] + " = " + params[index+2];
} eval(s);}};place.appendChild(el);
break; case "answer": new Wikifier(place, '<div class="answer-' + id + '">' + contents + '</div>');
break; case "append": new Wikifier(place, '<div id="' + macroName + '">' + contents + '</div>'); break; }}
else
{throwError(place, "<<" + macroName + ">>: cannot find a matching close tag");
}
},
};
macros["endchoiceblock"] = { handler: function () {} };
macros["endquestion"] = { handler: function () {} };
macros["endanswer"] = { handler: function () {} };
macros["endappend"] = { handler: function () {} };
}());
Comments
There is an HTML Code encoding error in the original code, you need to find and replace the double ampersands ...contain within one of the if statements with a logical and operator
This escaping error most like happened either during the process that convert the old forum to the existing one, or during a cut-n-paste operation.