Combing many Flags help

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.
Post Reply
Message
Author
User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Combing many Flags help

#1 Post by lsf22 »

Renpy 7.4.11

My question is say if I want many flags to to be checked before initiating a jump how would I do it? As I have many scenes flags It gets pretty messy and the line of code gets really long and it strikes me as not being the right way to do it.

Example: As I have more scenes to add it starts to get way too big for a line or is that okay? What if I have over 33 scenes for that one line?

Code: Select all

if scene_1 and scene_2 and scene_3 and scene_4 and scene_5 and scene_6 and scene_7 and scene_8  and scene_9 and scene_10 and scene_11==True:
        jump scene_12

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Combing many Flags help

#2 Post by Ocelot »

Can scene_11 flag be set without setting any of previous flags? If not, then flags it depends upon (and ones, those depends upon, and so on) are redundant and can be safely deleted.

Alternatively, you can use all() function, but you will still need to list all flags, so it just saves you from writing a bunch of "and"s.

Python does not really have a length limit, but editing such file can be cumbersome.

Also: ==True is almost always redundand and should be dropped. Since you are only comparing it to scene_11 and not others, I presume it is an artefact of copy-paste from elsewere, since all other flags are used properly without extra comparing.
< < insert Rick Cook quote here > >

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Combing many Flags help

#3 Post by lsf22 »

One of the things I was trying to accomplish is that when all 35 scenes are completed the player is met with a dialogue message that they completed all scenes. So it was not only for scene jumps but for that reason as well

I have wondered if this is good enough? For some reason I thought it may be flawed and with a scene accidentally being done out of order"

Example:

Code: Select all

    if scene_1 ==False:
        jump scene_1
    if scene_2 ==False and scene_1 ==True:
        jump scene_2
    if scene_3 ==False and scene_2 ==True:
        jump scene_3

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Combing many Flags help

#4 Post by Ocelot »

Generally this should be fine. You can get clever and stuff your scenes in a list and filter, but this is not nessesary. What is important is you understanding what is going on and being able of making changes.

An example of what I am talking about:

Code: Select all

 $ scene_list = [True, scene_1, scene_2, scene_3, scene_4]
if all(scene_list):
    jump all_done_message
else:
    $ next_scene = scene_list.index(False)
    jump expression "scene_" + str(next_scene)
Can you figure out how it works? Can you change this code if something must work differently? If not, you should not use it, even if it shorter, looks better and bug-free.

For your example I would test only for single scene here:

Code: Select all

if not scene_1:
    jump scene_1
if not scene_2: # You do not need to test for scene_1, because if it was not True, you would jump away before reaching this part
    jump scene_2:
if not scene_3:
    jump scene_3
jump all_done_message
Both my and your code works the same: sending player to the first scene he didn't see and showing message after seeing everything.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users