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 »

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: 255
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 »

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 »

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
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Change side images through Conditional switches

#4 Post by Imperf3kt »

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!"
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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 »

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

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Change side images through Conditional switches

#6 Post by rayminator »

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

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

Re: Change side images through Conditional switches

#7 Post by mitoky »

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!"

Post Reply

Who is online

Users browsing this forum: Google [Bot]