idmillington / undum

A client-side framework for narrative hypertext interactive fiction.
https://idmillington.github.com/undum
MIT License
336 stars 80 forks source link

Fixed 'null' in WordScaleQuality lists not behaving as you'd expect #40

Closed sequitur closed 9 years ago

sequitur commented 9 years ago

One of the features of QualityDefinition is that if the format() method returns null, nothing at all is written and the quality isn't displayed at all. You would expect that if one of the items in a WordScaleQuality is null, then that quality shouldn't be displayed at all as long as the quality is at that point in the scale; this is useful, for instance, for a quality that should only display if it is greater than some quantity (Eg, tracking wounds the player character suffered), a quality that depletes until it disappears entirely (Eg, tracking how much of a finite resource the player character has left), or a quality that is only visible if it is exceptional (Eg, in a game with many stats, showing only stats that aren't average).

Unfortunately, Undum currently doesn't behave this way. The reason why is line 479 in undum.js:

  return this.values[val] + mod;

Because mod is always a string, this line type coerces this.values[val] into a string, so that null becomes 'null'. I've added a line to check for null here and return an actual null value if that's the case, thus making it so the expected behaviour actually happens, making the interface here more consistent with the other QualityDefinition variants.

idmillington commented 9 years ago

Perfect. Thanks for the spot, and thanks for the fix!

sequitur commented 9 years ago

Great, thanks.