Alter Restart feature in JavaScript for Web Inkle? [Beginner]
Hi, I’m having trouble with the restart feature in my game. Specifically, I would like it to restart but preserve certain variables. I was wondering if there’s a way to alter the JavaScript that controls the Web restart feature to restart from a certain point in the inkle script. Is this possible? If not, how else can I preserve a list through resets? thanks so much for any help, I know this is probably a stupid question, but I’m still learning ^^.
No worries, there is no stupid question. Let me know if you have trouble with JS, because I just outlined the solution, I didn't give you the exact code.
Preserving variable throught the restart is totally possible: -> research where in the javascript is the code for the restart (where the logic for the tag RESTART is handled) -> copy in a js variable whatever variable you want to save.
var health = _inkStory.variablesState.$("player_health");
-> let the current code handling the reset of all variable. ->rewrite on the one you want to save just after the reinit has been done.
_inkStory.variablesState.$("player_health", 100);
you could also ask the question on the Inkjs that is responsible for the web port (https://github.com/y-lohse/inkjs).
To jump to a predetermined path is quite the same logic. (instead of rewriting the variable you want, just jump to the scene you want) (Documentation https://github.com/inkle/ink/blob/master/Documentation/RunningYourInk.md#jumping-to-a-particular-scene) I believe the command are exactly the same for the JS side as it's not listed as different.
Thanks @Selsynn! In case it saves time for someone else, here's what a complete reset function that preserves the example variable might look like:
function restart() {
var example = story.variablesState.$("example")
story.ResetState();
story.variablesState.$("example", example)
continueStory(true);
outerScrollContainer.scrollTo(0, 0);
}