Anatomy of a Bug (Patreon)
Content
Bugs are nothing new, but I thought this one was interesting enough to take some time and look at it. This bug in particular was in a new section of code that displays information about how many times a major scene has been triggered, so you can make an informed decision. In theory, it's a pretty simple piece of code looking something like this:
"You've been in this situation [the_scene.get_level_count()] times before, and expect an increase of [the_scene.get_resist_change()] to their resistance after."
Bonus points if you can spot the error already. It took me a few minutes of poking around to figure it out.
Ren'py allows you to insert python variables inside a text line by surrounding the variable name with square brackets. That's used multiple times throughout the game for things like quoting the date. "It is day [day]" would appear on the screen as "It is day 12" on day 12, and "It is day 84" on day 84, with no additional effort from me. It's a smooth, elegant system. So when I call the_scene.get_resist_change(0) inside a set of square brackets, it should display the expected resistance gain.
Except it doesn't.
The value inside of the square brackets isn't exactly resolved as code (despite properly allowing calls on object variables). It's taken as a string and a variable with that name is searched for. So rather than performing the function get_resist_change(0), it is looking for a variable called "get_resist_change(0)", which obviously doesn't exist. The trace (which lists the order in which commands were executed leading up to an error) looks even more confusing because this missing variable still looks like a function call.
All this has been resolved now. The values needed are calculated outside of the text now and stored in a temporary variable. This variable can then be called by name directly without any issues. I hope you enjoyed reading about this particular bug, it was certainly an interesting one for me to figure out.
EDIT: Patched version is now up, enjoy!