Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Hi,
I'm coding away on my VN and some of the IF / ELIF lines of code becoming longer and longer. Depending on the complexity of an event or interaction.
if ......
elif janitor_door_now_unlocked == False and class_b_tried_to_open == True and day >= class_b_eventcontinues_day and dtime >= class_b_eventcontinues_dtime and class_b_event_progress == 1:
jump janitor_unlocking_the_classroom_door
else:
......
Is there an elegant way to shorten this somehow, or to move the variable comparison somewhere else, so that the main code doesn't become so cluttered?
Maybe using a function call that returns a True or False to the IF statement?
Just using shorter variable names and labels isn't really an option, since the code needs to remain readable.
Thanks,
Kay
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.
Depends on what your conditions are, I guess. If you have non-boolean variables that need to be checked for equivalency, you can use a list. (if [var1, var2] == [1, 2] instead of if var1==1 and if var2==2, which is slightly shorter.) If you have a bunch of variables that are always going to be present, you could write a function, but it's unclear how much is generalizable based on what you've given.
Thanks for the tip philat, I'll try it out.
I am working on a sandbox game rather than a VN, so there is a lot of checking if a PC or NPC is at a certain location at a certain time, meeting a certain condition.
The variables are all True, False and numerical. As to be expected. Different vars for different NPCs.
I guess, at the end of the day there really is no elegant way to code complex game flows. Except having very short vars and a decoding table near by to know what they stand for.
But at least I figured out that I can use a single variable to keep track of the progress in a particular story branch. By increasing that var at every story node, there is a lot less comparing of individual vars needed.
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.
Well, what I meant was like this part: day >= class_b_eventcontinues_day and dtime >= class_b_eventcontinues_dtime and class_b_event_progress == 1
I don't know, since I don't know what the rest of your game looks like, whether this is something that would be collapsible into something like daytimeprogress("class_b") or daytimeprogress("class_a"), but it seems possible. Can't give concrete pointers without more information, but it may be something to explore.