borkshop / kni

An interactive story language in JavaScript inspired by Inkle’s Ink
MIT License
80 stars 10 forks source link

Does Kni support save state and other way to start the game? #64

Closed zeteticl closed 2 years ago

zeteticl commented 2 years ago

Sorry I am not a natural user of English, so I may not express well.

  1. Does Kni support save state ? Like i write a story which have 50 page. Could user save the variable and progress, and start again in old progress?

  2. I am developing a discord bot. I really want to add a story feature. Is there any way to call kni internally, like import require?

kriskowal commented 2 years ago

Yes, there are save and restore functions on the Kni Engine instance that produce a resumable JSON snapshot.

For example, in my story Peruácru, I reflect the game state as base-64 encoded JSON in the URL fragment (after #) so you can send a link to where you left off, and also capture it in local storage, so the game starts up where you left off even if you lose the fragment.

The code for Peruácru is also on Github as a practical demonstration of how to do all this, and also bind to a graphical scene if that is something you want to do.

Kni is first and foremost intended to be embedded in a web site, but you can debug your story with the kni command-line. The entire toolchain is JavaScript in the kni package on npm.

The most recently published version is usable. I’m not sure where we (me and @jcorbin) left-off in modernizing the code. You are welcome to help us drive the evolution of the engine. I don’t know of anyone else who is using it at the moment.

kriskowal commented 2 years ago

I would be negligent not to point you at Inke’s Ink, which Kni is based on but has had a lot more practical experience. You should compare your needs to what that provides as well. Ink is C♯ but I believe there are ways to deploy its stories to the web.