Change side images through Conditional switches

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
starshine001
Newbie
Posts: 23
Joined: Fri Feb 02, 2018 9:16 am
Completed: None
Projects: The Nightfall [Vampire Thriller]
Organization: None
Contact:

Change side images through Conditional switches

#1 Post by starshine001 » Sat Mar 17, 2018 2:46 pm

So, I want to let the player, at the beginning of the game, choose between two playable characters, Sarah and Alexandra. The only difference is the side image. I tried this code:

Code: Select all

# The script of the game goes in this file.

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define a = Character("MC", color="#04B4AE", image=ConditionSwitch("who=='2'", "alexandra", "who=='1'", "sarah"), window_left_padding=140)

image side a N = ConditionSwitch(
    "who=='2'", "side alexandra neutral.png",
    "who=='1'", "side sarah neutral.png")

# The game starts here.

label start:
    $ who = 2
    
    menu:
        "Who are you?"
        
        "Sarah":
            $ who = 1
            pass
        "Alexandra":
            $ who = 2
            
    a N "Test!"
But when I actually try it it doesn't display the side image. What am I doing wrong?
Looking cool, Joker!
-Morgana, 2017
----------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------
My dreams dictate my reality

User avatar
SleepKirby
Veteran
Posts: 246
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: Change side images through Conditional switches

#2 Post by SleepKirby » Sat Mar 17, 2018 4:03 pm

1 and '1' are different in Python. The first is an integer, the second is a text string. When you compare 1 == '1', you get a result of False.

Try changing the ConditionSwitch to use "who==2" and "who==1" instead.

User avatar
starshine001
Newbie
Posts: 23
Joined: Fri Feb 02, 2018 9:16 am
Completed: None
Projects: The Nightfall [Vampire Thriller]
Organization: None
Contact:

Re: Change side images through Conditional switches

#3 Post by starshine001 » Sun Mar 18, 2018 7:09 am

Thanks, SleepyKirby for the help!

Unfortunately, this doesn't seem to change anything - the image still refuses to show up. If anyone could give a working example I'd be very grateful.
Looking cool, Joker!
-Morgana, 2017
----------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------
My dreams dictate my reality

User avatar
Imperf3kt
Eileen-Class Veteran
Posts: 1752
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Change side images through Conditional switches

#4 Post by Imperf3kt » Sun Mar 18, 2018 7:40 am

Did you remember to change it in both places?

Code: Select all

# The script of the game goes in this file.

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define a = Character("MC", color="#04B4AE", image=ConditionSwitch("who==2", "alexandra", "who==1", "sarah"), window_left_padding=140)

image side a N = ConditionSwitch(
    "who==2", "side alexandra neutral.png",
    "who==1", "side sarah neutral.png")

# The game starts here.

label start:
    $ who = 2
    
    menu:
        "Who are you?"
        
        "Sarah":
            $ who = 1
            pass
        "Alexandra":
            $ who = 2
            
    a N "Test!"
Image

Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

User avatar
starshine001
Newbie
Posts: 23
Joined: Fri Feb 02, 2018 9:16 am
Completed: None
Projects: The Nightfall [Vampire Thriller]
Organization: None
Contact:

Re: Change side images through Conditional switches

#5 Post by starshine001 » Sun Mar 18, 2018 8:21 am

I did and it doesn't seem like your example changes anything either - maybe it has something to do with the files?
Looking cool, Joker!
-Morgana, 2017
----------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------
My dreams dictate my reality

User avatar
rayminator
Regular
Posts: 174
Joined: Fri Feb 09, 2018 12:05 am
Projects: Redoing games to fix spelling mistakes other companys that don't care
Location: Canada
Contact:

Re: Change side images through Conditional switches

#6 Post by rayminator » Sun Mar 18, 2018 9:20 am

this might not be what you are looking for sorry
in screens look for

Code: Select all

if not renpy.variant("small"):
        add SideImage() xpos 45 ypos 550
then in a new file or in the script add

Code: Select all

# side images #

image side Silvie:
    "4.png"
    size(150,165)

init python:
    config.side_image_prefix_tag = 'side'
then to define a character

Code: Select all

define si = Character("Silvie", image="silvie")
hope this helps it works for me
Image

User avatar
mitoky
Veteran
Posts: 280
Joined: Sat Feb 07, 2015 9:12 pm
Projects: CrossDol, The Purring Demon's Love, circus eterie
Organization: astellic
Tumblr: mitoky
Contact:

Re: Change side images through Conditional switches

#7 Post by mitoky » Sun Mar 18, 2018 10:20 am

You dont need to change both variables. Make the 1 the default character and leave it unchanged in the choice and when choosen the other simply do +1 for them to make it 2. Like this:

Code: Select all

#The script of the game goes in this file.

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define a = Character("MC", color="#04B4AE", image=ConditionSwitch("who == 1", "alexandra", "who == 2", "sarah"), window_left_padding=140)

#changed to make alexandra the "default" charcater, hence changed numbers
image side a N = ConditionSwitch(
    "who == 1", "side alexandra neutral.png",
    "who == 2", "side sarah neutral.png")

#variables should be defined with default outside of the labels. Make the default charcater the 1
default who = 1

# The game starts here.

label start:

    menu:
        "Who are you?"
        
        "Sarah":
            $ who += 1
            pass
        "Alexandra":
            pass
            
    a N "Test!"
Image

[Logo Commissions - OPEN] || Wish to support or tip me? Buy Me a Coffee!

Post Reply

Who is online

Users browsing this forum: No registered users