For a project I'm working on, I've evolved a bunch of tools for managing state vars. I'm in middle of a rewrite to fix some problems, but it's been pretty useful so far, and I thought I'd describe what I have, because I'm willing to work on augmenting or replacing sugarcube's current debugging tools with similar functionality.
This is the var-info display I have at the top of every passage:
Basics:
The text on the far right is the current passage name. This could be a history pop-up, but I haven't needed that yet.
This automatically detects what vars were read and written in the passage (using a js Proxy), and only shows those vars.
The middle section shows "flag1" was written but not read, and is currently true (green).
"flag2" was read but not written, and is currently false or null or undefined (red).
Clicking on "flag2" will toggle the value and redisplay the passage. Any boolean-ish value that's read can be toggled. (I also have some support for integer enums, but not general value editing yet.)
"flag3" was read and written, and is currently true. Hover will show the value before passage render and after. (Hover is not great for phone/tablet. I have an idea of how to fix that without cluttering the UI, but it's not been something that matters to me yet.)
"str" is a var that was written with a string value. Hover shows the full value.
(This UI is compact but maybe a bit too mysterious; I'd try to make it a little more legible in a general release.)
Big moods:
A var can be declared to be a "big mood" in a group of passages, eg, all passages that match /^ch1-/.
The idea is that a "big mood" should have an effect in most or all of the passages in the group.
Big moods are shown in the section on the left.
"dead" is a big mood, but this passage marks it as "ignore", because it doesn't need it, so it's shown faded out.
"isHappy" is marked in the passage as TODO, because the passage doesn't read it, and it's not marked "ignore".
Assertions/constraints:
There's a general assertion system that can verify that vars match some constraints in passagestart, and pop up a message if an assertion fails. This is helpful since toggling buttons can create states that are not reachable during normal play, and it's not useful to spend effort fixing the passage for that state.
For simple constraints, like $flag1 implies $flag2, toggling a flag will also automatically toggle other flags needed to satisfy the constraints. eg, if $hasTea implies $isHappy, then toggling hasTea to true will also set isHappy to true, and toggling isHappy to false will also set hasTea to false.
I'm also probably going to implement a checker to do depth-first traversal of the storygraph and report failed assertions.
For a project I'm working on, I've evolved a bunch of tools for managing state vars. I'm in middle of a rewrite to fix some problems, but it's been pretty useful so far, and I thought I'd describe what I have, because I'm willing to work on augmenting or replacing sugarcube's current debugging tools with similar functionality.
This is the var-info display I have at the top of every passage:
Basics:
Big moods:
/^ch1-/
.Assertions/constraints:
$flag1 implies $flag2
, toggling a flag will also automatically toggle other flags needed to satisfy the constraints. eg, if$hasTea implies $isHappy
, then toggling hasTea to true will also set isHappy to true, and toggling isHappy to false will also set hasTea to false.I'm also probably going to implement a checker to do depth-first traversal of the storygraph and report failed assertions.