Best way for select many characters?

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
Zebragirl
Newbie
Posts: 8
Joined: Fri Apr 05, 2013 3:54 pm
Contact:

Best way for select many characters?

#1 Post by Zebragirl »

Hello

I have many characters in my game (about 50 +) to choose,is there a way to select a character in the selection screen,excluding all others, without writing the list of "non-selected" each time?
In brief, I would select a character at a time.

more info:
1)whenever I select a character in my game,I have the possibility to change it whenever I want.
2)the characters are only available if unlocked

The code is that, it works, but with so many characters could become tiresome, if I need to rewrite every time the list of false:

Code: Select all

label Menu: 

menu:
            
            
            "Home":
                    "Back at Home"
                    jump Home
  
            
            "Character choice":
                    "choose a character"
                    jump Character_choice




label Character_choice:

menu:
            
        "Char1":
            #NOT SELECTED     
            if   char1 == False: 
              "unavailable"
              jump Character_choice
            #-----------------------------------------------------------------------------------     
            #SELECTED
            "selected!"
            $ char1_Load = True
            
            $ char2_Load = False
            $ char3_Load = False
            $ char4_Load = False
            $ char5_Load = False
            jump Menu
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                
        "Char2":
            #NOT SELECTED
            if   char2 == False: 
              "unavailable"
              jump Character_choice
            #-----------------------------------------------------------------------------------     
            #SELECTED              
            "selected!"
            $ char2_Load = True
            
            $ char1_Load = False
            $ char3_Load = False
            $ char4_Load = False
            $ char5_Load = False
            jump Menu
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                
        "Char3":
            #NOT SELECTED
            if   char3 == False: 
              "unavailable"
              jump Character_choice
            #-----------------------------------------------------------------------------------     
            #SELECTED              
            "selected!"
            $ char3_Load = True
            
            $ char1_Load = False
            $ char2_Load = False
            $ char4_Load = False
            $ char5_Load = False
            jump Menu          
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                
        "Char4":
            #NOT SELECTED
            if   char4 == False: 
              "unavailable"
              jump Character_choice
            #-----------------------------------------------------------------------------------     
            #SELECTED              
            "selected!"
            $ char4_Load = True
            
            $ char1_Load = False
            $ char2_Load = False
            $ char3_Load = False
            $ char5_Load = False
            jump Menu                        
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        "Char5":
            #NOT SELECTED    
            if   char5 == False: 
              "unavailable"
              jump Character_choice
            #-----------------------------------------------------------------------------------     
            #SELECTED
            "selected!"
            $ char5_Load = True
            
            $ char1_Load = False
            $ char2_Load = False
            $ char3_Load = False
            $ char4_Load = False
            jump Menu           
        
        
#-------------------------------------------------------------------------------------------  
Thanks.

Tsapas
Regular
Posts: 69
Joined: Mon Oct 14, 2013 8:18 am
Contact:

Re: Best way for select many characters?

#2 Post by Tsapas »

Well, a solution would be this (though somewhat quick and messy, you could further improve it by using lists or something, especially for lots of characters).

Code: Select all

label Menu: 

menu:
            "Home":
                    "Back at Home"
                    jump Home
  
            
            "Character choice":
                    "choose a character"
                    jump Character_choice

label Character_choice:

menu:
            
        "Char1" if char1 == True:  #this way the option will only show when conditions are met, e.g. Char 1 is unlocked.
            "selected!"
            $ char_Load = "char1"
            jump Menu
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                
        "Char2" if char2 == True:          
            "selected!"
            $ char_Load = "char2"
            jump Menu
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                
.
.       
.        
#------------------------------------------------------------------------------------------- 
Though it would need a bit of alteration in selected character load code to take the char value from $char_Load

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Best way for select many characters?

#3 Post by xavimat »

I see here different issues:
1. The most important, I'd chose a simpler way to know what character is currently selected. Instead of a different boolean variable for each one (char1_Load; char2_Load; char3_Load;char4_Load...). I'll use only one with the number of the selected character:

Code: Select all

$ char_load = 1 # or whatever the number is
This way, you don't need to change all the other variables to False when selecting.
2. In the menu, you can present only the unlocked characters and hide the locked adding the "if" statement this way:

Code: Select all

menu:
    "Char1" if char1:
        "selected!"
        $ char_load = 1
    "Char2" if char2:
        "selected!"
        $ char_load = 2
This way, the player can't see the non-available characters.

But, if you want all the names visible and only some of them selectable, here there is a more complex way:

Put this somewhere in your script files:

Code: Select all

init python:    
    char_names = [ "Name 0", "Name 1", "Name 2" ]   # Here the actual names of your characters. You can add all the names you want.
    chars = [ ]
    for i in char_names:
        chars.append([i, None])
    char = 0    # Selected by default the first character (the first has the number "0", the second has "1")
In the game, the player can choose with this:

Code: Select all

$ char = renpy.display_menu(chars)  # this presents the menu
The selected char:

Code: Select all

$ name = char_names[char]  # the variable "name" stores the current character's name.
"You have selected [name]."
All characters are initially locked. You can unlock them with this:

Code: Select all

$ chars[0][1] = 0  # to unlock the first character (number 0)
$ chars[1][1] = 1  # to unlock the second character (number 1)
$ chars[2][1] = 2  # to unlock the third character (number 2)
... 
# There is a "1" that never changes!
Remember, you can't present the menu with all the characters locked, because the player can't select anything. Yo need to unlock at least one.

You can lock again a character this way:

Code: Select all

$ chars[2][1] = None  # Locks the third character (number 2)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: MisterPinetree