Ren'py Statement Equivalents and Uniform Management work
Added 2021-06-12 06:38:25 +0000 UTCThe initial release of v0.41.1 contained a bug that caused crashes during certain sections of dialogue. That bug was addressed in v0.41.2 (which you can get here), and I thought the root cause was interesting enough to talk about, and that my experiences might help some other Ren'py dev out there. I've also been working on some changes to the Uniform management system for your business, which I'll talk about a little more at the end of this post.
The bug was introduced with the change in Ren'py versions that took place in v0.41, specifically because of the way the new version handles something called a "statement equivalent". Ren'py dialogue and actions are written in a way that looks similar to a traditional script. A section of dialogue might look like:
lily "Hello there!"
mc.name "Hey!"
"You enter the room and see [lily.title] inside."
$lily.draw_person()
Each line tells Ren'py who is talking (or if it's narration, if nobody is given). Extra symbols, like variables inside of square brackets or lines that start with a dollar sign, tell Ren'py that something other than pure dialogue is needed. The Ren'py format is very quick for writing visual novel style dialogue and actions, which is why it's useful.
It's important to know that Ren'py is actually just an interpretation layer. When you run a Ren'py application it's actually a python application that is translating the Ren'py script into python instructions that decide how text needs to be shown on screen, positioned, ect. When a line starts with a $ this is actually an indication that what is being run there is pure python code itself, with no interpretation needed.
Because of this interpretation it's possible to do all of the normal Ren'py things using pure python code. These are called "statement equivalents. Dialogue, for example, can be written as:
$ renpy.say(lily, "Hello there!")
Statement equivalents are useful because Python offers many features that would be too complex to implement in pure Ren'py. Many sections of Lab Rats 2 use python statements to display dialogue or show characters. To support the procedural recoloring of dialogue and character names I had made modifications to some of the python code that Ren'py uses to display text. Ren'py v7.4.5 changed the way Ren'py vs. Python dialogue calls were processed though, so there was an inequality between them. Because of this Python calls would crash out, but pure Ren'py statements worked perfectly.
The fix was simple, and have been how I originally implemented the system if I knew as much about Ren'py as I do now. When processing say statements Ren'py accepts two things as the speaking character: A string, which it uses as-is, and a "runnable". A runnable is a function which can be run and returns a string to use. Python is very flexible about what can be made runnable, and I recently discovered it allows you to treat entire classes as runnable. I made the Person class runnable (by implementing a __call__ function) and moved all of the text customization out of Ren'py's code and into the Person class definition. This means Lab Rats 2 now uses an unmodified Ren'py installation, which should make it easier to mod and update to newer versions of Ren'py in the future.
I've updated the dialogue integration test to check that both Ren'py and Python dialogue functions properly, so this sort of bug shouldn't pop up in the future!
With that bug finished off I've started development on v0.42. During my test game of v0.41 I realized I was avoiding setting company uniforms because of how tedious and unintuitive it was. I'm tackling that right away with a new uniform management system. The goal is to take all of the current functionality and condense it down to a single screen. From that screen you will be able to preview all of the uniform outfits you currently have set, add a new outfit to the uniform list, and select what departments that uniform applies to. I am also making it possible to have a single uniform be flagged to be both a full outfit and an underwear/overwear set.
I'll have some more details and preview pics of the uniform management system as I finish it up in the next couple of days.
Comments
looks like they are two instances of the_prson instead of the_person in crises.rpy
2021-06-26 16:21:15 +0000 UTCSo I got the worker wanting you to hire her daughter event. I got two options, look at the resume and tell her we are not hiring. I choose we are not hiring and got this error [code] I'm sorry, but an uncaught exception occurred. While running game code: File "game/script.rpy", line 288, in script call call advance_time from _call_advance_time_15 File "game/script.rpy", line 422, in script call $ the_crisis.call_action() File "game/crises/regular_crises/crises.rpy", line 2681, in script $ the_prson.change_obedience(1) File "game/crises/regular_crises/crises.rpy", line 2681, in $ the_prson.change_obedience(1) NameError: name 'the_prson' is not defined -- Full Traceback ------------------------------------------------------------ Full traceback: File "game/script.rpy", line 288, in script call call advance_time from _call_advance_time_15 File "game/script.rpy", line 422, in script call $ the_crisis.call_action() File "game/crises/regular_crises/crises.rpy", line 2681, in script $ the_prson.change_obedience(1) File "renpy/ast.py", line 934, in execute renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store) File "renpy/python.py", line 2218, in py_exec_bytecode exec(bytecode, globals, locals) File "game/crises/regular_crises/crises.rpy", line 2681, in $ the_prson.change_obedience(1) NameError: name 'the_prson' is not defined Windows-10-10.0.19041 Ren'Py 7.4.5.1648 Lab Rats 2 - Down to Business v0.41.2 Sat Jun 26 12:14:06 2021 [/code]
2021-06-26 16:16:37 +0000 UTCI would love to see a small expansion to the wardrobe as well. I know it might be useless for me to say, but I love seeing little implements to each update!
jimmy jimmy
2021-06-17 02:28:31 +0000 UTCI tend to completely avoid setting uniforms for a good part of the game so that I don't have to deal with staff who either don't like uniforms or happen to clash with them in some other way like colour or skimpiness. (In fairness I have no idea if colour factors in at all or if it's an empty value trait like not liking sports.) But particularly in the early game when I don't have the charisma to compliment-boost them back to a happy state, spending money to unlock uniforms seems like a waste of resources.
Dreamdayer
2021-06-15 16:05:45 +0000 UTCSomething you might want to look at with uniforms - at present, if you set a uniform that an employee doesn't want to wear (high sluttiness for the uniform), it's possible that every time you interact with that character you get a new punishment for them not wearing the uniform. This is the case even if you've demanded they go naked or wear a punishment outfit. Acts as somewhat of an exploit (as you can force them to change, increasing their obedience, plus of course you get the extra punishment option) but more to the point, since you can only adminster a punishment to a girl once per day, the interface can get somewhat unwieldy.
GAZZA
2021-06-14 04:31:39 +0000 UTCVery interesting. Also that new uniform system sounds way more convenient.
2021-06-13 18:03:38 +0000 UTCThanks for the informative mini lecture, this was rather interesting!
Colin T.
2021-06-12 17:18:01 +0000 UTC