Revision of Twine: eliminate the back button functionality in Sugarcane from Tue, 02/26/2013 - 01:50

If you want to remove the browser's Back button functionality in Sugarcane, to prevent the player from rewinding or undoing moves, here is some script code that can do that:

History.prototype.save=function(c){var a="";for(var b=this.history.length-1;b>=0;
b--){if((this.history[b].passage)&&(this.history[b].passage.id)){a+=this.history[b].passage.id.toString(36)+".";
}}this.history[0].hash="#"+a.substr(0,a.length-1);if(this.hash){return"";}this.hash=this.history[0].hash;
return this.hash;};History.prototype.restart=function(){window.location.reload();
};macros["return"]=macros.back={handler:function(a,b,e){var f=RegExp(String.fromCharCode(92)+".","g");
var c="";var d="";var f="";if(e[0]){if(e[1]=="steps"){if(isNaN(e[0])){throwError(a,"parameter before 'steps' must be a number.");
return;}else{if(e[0]<state.history[0].hash.match(f).length){d=state.history[e[0]].passage.title;
}}}else{if(tale.get(e[0]).id==undefined){throwError(a,"The "+e[0]+" passage does not exist");
return;}h=tale.get(e[0]);h=new RegExp("("+f.toString()+"|#)"+h.id.toString(36));if(h.test(state.history[1].hash)){d=e[0];
}}}else{d=state.history[1].passage.title;}if(!d){return;}else{el=document.createElement("a");
el.className="return";el.onclick=function(){state.display(d,el);};
el.href="javascript:void(0)";el.innerHTML="<b>«</b> "+b[0].toUpperCase()+b.slice(1);
a.appendChild(el);}}};

This will prevent previously visited passages from appearing in the player's browser history, except for the Start passage (since it's loaded before custom scripts are, unless you're using a later Twine alpha), and any passages revisited using the Rewind menu. (With this code, that seemingly vestigial menu could be made more important.)

Note: this code replaces the <<back>> and <<return>> macros so that they no longer alter the page URL hash. As a result, they are identical in function (except for the words 'back' and 'return' in the generated links).

pensive-mosquitoes