[Tool] Convert Choicescript to a Graphviz .dot file

I found a github repo that converts choicescript to a graphviz .dot file. Here’s my fork of it: GitHub - Flurrywinde/choicescript-graphviz: visualize ChoiceScript files as graphs using graphviz/dot

If you can get it working, it can produce output like:

Zoomed in on just part of it:

Sadly, it’s incomplete, and I had to jerry-rig it to not error out on things like *gosub, *return, *else, etc.

It’s in java, so you have to compile it. Then you need a graphviz viewer like xdot.

I’m wondering if this could be put on the web somewhere, so people could upload or paste in their choicescript, hit a button, and get the resultant flowchart. Anyone know how to do that?

16 Likes

Oh I’ve been wondering if something like this was possible! I’ll definitely be following this topic. I’m sure many others would be interested in creating flowcharts if someone can get a simplified tool up somewhere for popular use

Interesting find!

Unfortunately with it being Java, you’d need to host it on a server somewhere (i.e. it’d cost some money to host, and time in maintenance). By no means impossible, but it raises the bar a little for a hobbyist.

Note #1: The choicescript .txt file must use tabs for indentation (not spaces).

This is a pretty big limitation. Worth noting in the first post?

4 Likes

Maybe, but it’s pretty easy to fix, I think. I forget what it’s like to not be a programmer sometimes. I just did retab! in vim to convert spaces to tabs. Maybe just for fun I’ll learn enough java to support spaces too, as this kind of flowchart is something I’d get a lot of use out of. Maybe others will as well if we can get it into an easily usable form.

2 Likes

Yeah, I’d wager 80-90% of the forum have no clue what vim even is :grin:

4 Likes

Very cool. Reminds me of how Twine displays branches and passages. Would definitely be interested in seeing it developed further.

1 Like

I’d wager higher :joy:.

I’ve been growing less and less interested in ChoiceScript itself (still like IF though), but this problem seems interesting and not that hard.

You don’t even need a full parser, you only need to parse flow control commands such as goto, gosub, if and their variations, and labels. Then build a tree and plot using D3.js or something similar. If you use only JavaScript then you can run it in any browser locally.

1 Like

I still hope to do this in D3.js someday, but D3 is a bit daunting to learn. However! I finally did a bit more work on this the past few weeks.

It all started when I happened upon a python module called Rich, which can make good-looking trees. I used it to make the following:

It’s still just a prototype, but it can already open and close branches and analyze a scene’s stats.

Then I made Choicescript Analyzer which converts it back into graphviz after condensing the tree down to just the parts relevant to analyzing the tree for the different values all the stats can be. This was the hardest part for me when making games, so I’m really excited. I’m going to make a new post about just this tool now.

2 Likes