Typescript/Svelte IF Framework

I think you can just forward the requests to the VSCode JS language server if the location is within a JS attribute.

Since my users will be working with Typescript, complex logic will be defined by the user as a typescript function. And looking at Rez code: The barrier to just full-blown JS/TS isnā€™t that high. Thatā€™s my reason to sticking with TS instead of making my own declarative format: If you want the format to be sufficiently capable, you might as well let the user use JS directly, because the complexity of learning it is similar.

Itā€™s an interesting question. I feel like I have attempted to let JS be useful but keep it ā€œin a boxā€. That probably reflects my own bias here which is that I use JS out of necessity (browser) rather than any desire for the language itself.

Donā€™t get me wrong, I also donā€™t like plain JS, but with TS you can get the illusion of static typing, which is enough for me.

Have you heard about WebAssembly by any chance? You donā€™t have to stick to JS. Rust has great support for WASM, and the dioxius library for rendering in the browser that is React-like. Dart also had good web support I think, for C/C++ thereā€™s Emscripten.

I had a look around to see what DSLs are currently in use and popular, and I think Iā€™ve settled on ChoiceScript as an additional format I want to support and Adventuron code for my parser world model implementation.

That of course requires open-source re-implementations in Typescript for both of these, letā€™s hope I donā€™t get sued lol. But since Iā€™m not naming my product after theirs and donā€™t use their code, they shouldnā€™t have a legal standing anyways.

1 Like

In a different universe I might have targeted WA but while I am familiar with it at a conceptual level, Iā€™ve never used it. I did ponder rewriting the whole shebang in Rust a year ago (while Elixir is a language I love, itā€™s not the best fit for distributable command-line tools) but decided it wasnā€™t worth the effort.

IIRC the Choicescript guys are pretty open and approachable. If it were me, Iā€™d confirm they donā€™t have a problem with it rather than risk annoying them later. Itā€™s not that I think they would sue you,ā€¦ but they seem to have a good rep in the community, why risk getting on the wrong side of them?

1 Like

Dan Fabulich @dfabulich is a very approachable guy. Heā€™s the man to talk to about ChoiceScript/CoG and frequents here quite often. Hereā€™s an interesting thread, mostly surface level discussionā€¦ How difficult is choicescript to duplicate?

The Adventuron fellow, Chris Ainsley @adventuron , is easily found on his Discord channel.

I could see a huge benefit of both those engines working more seamlessly with JS/CSS. However, the CoG format is a pretty specific with their publishing standards. You might have the functionality of ChoiceScript, but not a valid format for their storefront. Anyway, Iā€™m talking out of my ass about this now. Those two are who you want to talk to. :wink:

Can you help me understand what youā€™d hope to accomplish by interpreting other IF languages as ā€œformatsā€ in IF Framework? It seems like it would allow people to write games in ChoiceScript/Adventuron/etc. that run in the IF Framework.

But isnā€™t the point of IF Framework that authors would develop IF in TypeScript/Svelte and not to write in a DSL like ChoiceScriptā€¦?

As a word of encouragement, I think the world needs a modern IF framework that lots of people use that relies on a modern, popular programming language, and I hope your framework is the one to make that happen.

But, as a word of warningā€¦

From time to time, IF enthusiasts come to the table with alternate IF authoring systems in which authors can develop IF in a ā€œrealā€ programming language, typically one of the top 20 languages on StackOverflowā€™s ā€œmost loved languagesā€ list. Stack Overflow Developer Survey 2023

But none of the most popular IF systems require authors to use a ā€œrealā€ programming language. Instead, since most IF authors see themselves as writers first and coders second (if at all), all of the most popular systems use a domain-specific language for IF, ideally one that makes it easy to write extensions in another ā€œrealā€ programming language (typically JavaScript).

I think that this is because authors who know JS/TS tend not to use other peopleā€™s enginesā€¦ instead, they write their own engine, like you did. But maybe your framework will be the one that finally breaks through!

In my experience, the language of your IF system is arguably the least important factor in making it popular. The most important factor is to implement an entire complete ā€œadmirableā€ game. Most people decide to use an IF system because they see a game that they admire, and they say, ā€œI want to make a game just like that! Whatever system the author used to make it, Iā€™ll use that system, too!ā€ Admirers donā€™t seem to directly care about any of the details of the system, except that if itā€™s too hard for them to learn the system and finish a game, thatā€™s a major factor in achieving true popularity.

And thatā€™s a great opportunity for you, because it means that you donā€™t actually have to persuade anyone to adopt your framework except yourself. Make a great game (a few great games) and others will follow.

(Having said that, there is something to be gained from looking at other open-source games and porting them to your framework, to ensure that youā€™ve covered all the functionality that those other games might need. But thatā€™s very different from just interpreting those other games, unmodified, in my experience.)

Good luck!

11 Likes

This was good advice when you gave it to me, and it remains good advice today!

3 Likes

The problem is that Svelte and Typescript can be very verbose for some things, and ChoiceScript concise syntax for many common things in choice-based games. I would implement a subset of ChoiceScript (the one that describes a single scene since that corresponds roughly to a passage in my system), so you can use ChoiceScript for the parts of your game that neatly fit that model, and fall back to Svelte when you have something complex or layout-heavy thatā€™s not supported. Thatā€™s the model I currently have already with Markdown passages, but markdown is too limited for most things and only really usable for plain prose. ChoiceScript would serve as more of a layer in the middle. Iā€™ll decide between ChoiceScript and Ink as an additional format for now, I have to read up on Ink a bit so see which is more versatile. That said Ink already gets a bonus because it has an existing JS library. But ChoiceScript has a bonus of being more popular, so more people are likely to already know it.

Ideally I would also support a no-code style with ChoiceScript: Just create a project from the template and create passages in ChoiceScript, no additional coding needed. Can you write JS plugins for CoGā€™s Hosted Games by the way? Or would that interfere with the packaging as native apps? I also want to include a way of creating native apps instead of just websites, and Iā€™ll do that with Tauri probably.

Thatā€™s why Iā€™m not making an engine in the strict definition, itā€™s more of a collection of modules that you can use that also happen to fit neatly together as an engine. Donā€™t like the UI? You can replace that. Donā€™t like the concept of passages for your game? Set the history size to 0 and simply use a ā€œpassageā€ as a distinct screen in you game. Or even just have one ā€œpassageā€ and do everything with Svelteā€™s dynamic UI if you want.

I would like to make things even more modular, but the communication between the modules becomes difficult if you donā€™t have one central singleton to refer to. I do plan on having the parser game module usable in the choice model though, so youā€™d be free to mix and match both if needed. Display a choice-based UI that can also be interacted with via a parser? completely doable.

Maybe thatā€™s the reason the current systems arenā€™t appealing for someone with a programming background: The ones created by programmers just never got anywhere and died, because most programmers are (if the notorious ā€œprogrammer artā€ is anything to go by) probably bad writers.

The game ideas I have are mostly someone elseā€™s IP, but I donā€™t expect them to be big successes, nor commercial. Thereā€™s the German saying ā€œWo kein KlƤger, da kein Richterā€ (ā€œNo plaintiff, no judgeā€ according to google translate), and I havenā€™t heard about fanfiction actually getting sued, the worst that could happen is that I have to take it down again if it catches too much attention.

I have a few big original ideas, but most are a better fit for other game genres, though for one making it a parser game may actually simplify certain thingsā€¦

Yeah, currently I pretty much follow the Twine model, but itā€™s generic enough you should be able to fit anything else into it, really. Especially when you can just write generic Typescript and Svelte code. The question is then how much of the additional work needed for the game is generic enough to be included in the framework.



Another thing I can see as a cool possibility is becoming something like the GraalVM of IF: Someone created a great character editor in Ink, but you prefer ChoiceScript? No problem! The framework will handle the integration of them. At least for choice-based games that should work, because abstractions like ā€œpassagesā€ and ā€œvariablesā€ are pretty much universal. From the brief look I had at parser games, the world models used seem to differ, so that would be more of a challenge.

Right, and that is not my goal anyways (in contrast to the thread you linked, I really just want to replicate the language). I just think ChoiceScript is a nice language for simple choice-based games, and if I can make a functional VSCode extension for it (which shouldnā€™t be hard once I have made a parser), it should also be enough for my standards code-completion wise. I also think itā€™s more concise and readable than Ink.

@dfabulich Does the ā€œMake Your Own Gamesā€ pages and the subpages contain all commands and such that are available in the language, or are there some things not detailed there?

ChoiceScript is open source (in the informal sense that the source code is available to look at, not the formal sense that itā€™s got a license letting you use it for any purpose), so if youā€™ve got permission to use the language, you can look at the specs and the reference implementation too!

Similarly Ink is MIT-licensed and has bindings for Unity, Unreal, and plain JavaScript.

I donā€™t know Adventuronā€™s license off the top of my head.

1 Like

Specs yes, reference implementation probably no (I couldnā€™t make sure I donā€™t subconsciously use some of the code or patterns in that case). And the only ā€œspecsā€ I could find is the documentation on the website, and thatā€™s not a formal definition, more a tutorial.

Yep, I found that already. JS bindings are neat, but I probably only need the JSON format specification, since Iā€™ll probably have to build the actual player myself to integrate it better.

I didnā€™t find anything about Adventuron, really. The website has no license, thereā€™s only a bug tracker repository, and the only way to use it seems to be the online editor.

I think this is the last Adventuron package that was made availableā€¦
Adventuron Classroom 1.0.0 beta 68j (March 2021) : Chris Ainsley : Free Download, Borrow, and Streaming : Internet Archive

Adventuron has a few online editor linksā€¦
Regular ā†’ https://adventuron.io/classroom/
Secret ā†’ https://adventuron.io/beta/
Super Secret ā†’ https://adventuron.io/betabeta/

Anyway, I really like Adventuronā€™s syntax. I wish Adventuron had an official offline way of making games.

Yeah, it has the easiest and nicest syntax of all parser engines I looked at so far.

If you scratch the ā€œofficialā€, looks like Iā€™m about to make that happen :wink:.

Iā€™ll concentrate on choice-based games and polishing first before tackling parser games though.

1 Like

I made another demo game btw, including the source code.

1 Like

If anyone gets where I have the name of the spaceship (and the whole story, really) in the game from by the way, Iā€™m seriously impressed.

Hereā€™s one tip:

A German sci-fi book series

I also made an accessibility update: I tweaked the standard color palette a bit to match contrast requirements and the entire UI is now navigable by keyboard. I also added some more hotkeys:

  • ctrl + s: Open the save dialog
  • Escape: Close the topmost dialog
  • ctrl + left/right arrow: Navigate the history
  • ctrl + shift + r: Reset the story
1 Like

No, Iā€™d say that ChoiceScriptā€™s documentation is not complete; it certainly doesnā€™t have anything like a formal ā€œspecification.ā€

Twine is more popular than ChoiceScript or Ink combined. Hereā€™s a quick SQL query I just ran over the public IFDB database export:

MariaDB [ifdb]> select count(id), system from games
where created > '2023-01-01'
group by system order by count(id) desc limit 10;
+-----------+--------------+
| count(id) | system       |
+-----------+--------------+
|       345 | Twine        |
|       105 | Ink          |
|        95 | ChoiceScript |
|        84 | Inform 7     |
|        68 | NULL         |
|        37 | Custom       |
|        25 | Moiki        |
|        21 | Inform 6     |
|        17 | Adventuron   |
|        16 | Ren'Py       |
+-----------+--------------+

So, if youā€™re picking formats to interpret or fork from, Twine seems like the slam-dunk winner.

This already sounds a lot like how Twine works, where you can use the GUI editor to create and define passages, but you can also add JavaScript to any passage, or to the game as a whole.

Iā€™m not sure Iā€™ve fully wrapped my head around your goal here, but if I said to myself, ā€œI really like Twine/ChoiceScript/Adventuron, but I wish they supported TypeScript and Svelte for the tricky stuff,ā€ hereā€™s how Iā€™d handle it.

And, with that, Iā€™d declare victory, and start writing a bunch of great interactive fiction in my new Twine TypeScript/Svelte story format.

2 Likes

That is feasible, but the one big problem is the language server support. Thatā€™s the main reason for Typescript, and Svelte is also much easier with it. The VSCode Typescript language server and the Svelte extension are open-source, but Iā€™d have to rewrite them to work with CodeMirror. There seems to be a CodeMirror language server plugin, but that works over WebSockets, not in the same tab, so Iā€™d need to rewrite that a bit, too. And currently the editor plugins in Twine donā€™t get access to the whole story, just the current passage, which would make things like imports impossible to resolve.

And using Twine as a base has not much benefits except userbase (and many of the Twine users probably arenā€™t interested in heavy use of Typescript in their stories): The Twine application does almost nothing except provide a graphical editor (which you can also have in VSCode, and the tabs in VSCode are much better than in Twine IMO), the rest is provided by the story format anyways. The passages are provided in the HTML blob the story format gets, but the actual implementation in logic and UI has to be done yourself anyways. Iā€™d rather get the power of a dedicated editor in combination with the standard JS build tooling. Twine also currently doesnā€™t really have a system for assets, Webpack does.

I can probably make a story format based on IF Framework, but thatā€™s not a priority for me. In the meantime I have however figured out everything that is possible in ChoiceScript (at least with all the commands in the documentation), and Iā€™m a bit surprised negative numbers donā€™t work and you need parentheses for everything. Since I already have to make a parser, I might as well make a ChoiceScript dialect where thatā€™s supported. I already made a Lua parser, so I can just mostly copy the operator precedence code from that one.

The reason why I favor ChoiceScript over Ink: When I look at a ChoiceScript file, I can immediately read it and see what it does. Ink works much more with special characters than commands. Ultimately, I want to support both though.

1 Like