Page 1 of 1

Change side images through Conditional switches

Posted: Sat Mar 17, 2018 2:46 pm
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?

Re: Change side images through Conditional switches

Posted: Sat Mar 17, 2018 4:03 pm
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.

Re: Change side images through Conditional switches

Posted: Sun Mar 18, 2018 7:09 am
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.

Re: Change side images through Conditional switches

Posted: Sun Mar 18, 2018 7:40 am
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!"

Re: Change side images through Conditional switches

Posted: Sun Mar 18, 2018 8:21 am
by starshine001
I did and it doesn't seem like your example changes anything either - maybe it has something to do with the files?

Re: Change side images through Conditional switches

Posted: Sun Mar 18, 2018 9:20 am
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

Re: Change side images through Conditional switches

Posted: Sun Mar 18, 2018 10:20 am
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!"