Changing the side-image according to gender choice

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
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Changing the side-image according to gender choice

#1 Post by bellice »

What I want is - theoretically - very simple. The player gets to choose between a male and a female player character in the beginning.
Depending on what was chosen, I want Renpy to display different side images.

Now I've been looking for tutorials and hints, and I've been working with the tips in this thread. And it works, but only when I don't use side images.

Code: Select all

init:

    
    $ mc = Character("Jordan", 
        who_ypos=-23,
        who_xpos=230,
        who_font="ui/Arsenal-Regular.otf",
        who_outlines=[(3, "#000000", 0, 0)],
        show_side_image=???,
        what_ypos=-30,
        what_xpos=200,
        what_color="#FFFFFF",
        what_outlines=[(3, "#000000", 0, 0)])
        
        
# The game starts here.
label start:
    
    $ gender = "female" #default needs to be present
    
    
    
    scene hallway with dissolve

    n "The shackles bite painfully into my skin."
    n "They are just a tad too tight to be comfortable, no doubt on purpose."
    n "The two men walking on either side of me do so silently, their eyes stubbornly focused in front of them and their expressions grim."
    n "I assume they're male, anyway."
    n "Can't be too sure when it comes to other civilisations, especially in this backwater quadrant."
    n "I test my cuffs, trying to wiggle out of them."
    n "No dice."
    guard "You won't be able to escape these. They're reinforced titanium, uhm..."
    n "Obviously they're not too sure about our gender conventions, either."
    
    menu:
        "Ma'am.":
            $ gender = 'female'
            "Ma'am. I'm female."
            guard "Very well, Ma'am. I'd advise you to keep your hands still. You'll hurt yourself otherwise."
            
        "Sir.":
            $ gender = 'male'
            "Sir. I'm male."
            guard "Very well, Sir. I'd advice you to keep your hands still. You'll hurt yourself otherwise."
            
    mc neutral "You're surprisingly polite, considering you've just arrested us for murder."
    n "Somewhere behind me, there's a groan."
    l "Your sense of tact is as immaculate as always."
    mc annoyed "Just wait till I shove my tact right up your-"
    "The guard clears his throat."
    guard "It is customary in our society to treat prisoners with respect, no matter their crime."
    mc neutral "So you're not gonna throw us in a cell to starve?"
    guard "No. We do not stoop to your level."
    mc angry "My level? You listen here, twerp, I-"
    l "What WILL you do with us?"
    n "Asshole."
            

    return
So this is what my code currently looks like and I've been playing around, but I have no idea how to get the side image to work.
Along with that, I have another file called 'xLiveComposite.rpy', like OokamiKasumi suggested in the thread, which looks like this:

Code: Select all

init-1:

    image mc = "mc/MC female/fmc_neutral.png"
    
# --------------------------

    image mc neutral = ConditionSwitch(
        "gender == 'female' ", Image ("mc/MC female/fmc_neutral.png"),
        "gender == 'male' ", Image ("mc/MC male/mmc_neutral.png"),
        "True", Image ("mc/MC female/fmc_neutral.png"),
        )
    
    image mc annoyed = ConditionSwitch(
        "gender == 'female' ", Image ("mc/MC female/fmc_annoyed.png"),
        "gender == 'male' ", Image ("mc/MC male/mmc_annoyed.png"),
        "True", Image ("mc/MC female/fmc_annoyed.png"),
        )
    
    image mc pleased = ConditionSwitch(
        "gender == 'female' ", Image ("mc/MC female/fmc_pleased.png"),
        "gender == 'male' ", Image ("mc/MC male/mmc_pleased.png"),
        "True", Image ("mc/MC female/fmc_pleased.png"),
        )
    
    image mc angry = ConditionSwitch(
        "gender == 'female' ", Image ("mc/MC female/fmc_angry.png"),
        "gender == 'male' ", Image ("mc/MC male/mmc_angry.png"),
        "True", Image ("mc/MC female/fmc_angry.png"),
        )
Basically, no matter what I add after show_side_image, I always get an error like

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game\script.rpy", line 69, in script
Exception: Say has image attributes (u'neutral',), but there's no image tag associated with the speaking character.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\execution.py", line 266, in run
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\ast.py", line 401, in execute
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\exports.py", line 750, in say
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\character.py", line 731, in __call__
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\character.py", line 692, in resolve_say_attributes
Exception: Say has image attributes (u'neutral',), but there's no image tag associated with the speaking character.
I've been trying all kinds of options, but usually coding for me involves looking up a tutorial, copy-pasting the code and replacing the relevant bits. In other words, I have no idea what I'm doing.

I hope you guys understand my rambling. Help?

philat
Eileen-Class Veteran
Posts: 1926
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Changing the side-image according to gender choice

#2 Post by philat »

http://www.renpy.org/doc/html/side_image.html

You declare the side image in the Character by using image="(tag)".

Code: Select all

    $ mc = Character("Jordan", 
        who_ypos=-23,
        who_xpos=230,
        who_font="ui/Arsenal-Regular.otf",
        who_outlines=[(3, "#000000", 0, 0)],
        image="mc",
        what_ypos=-30,
        what_xpos=200,
        what_color="#FFFFFF",
        what_outlines=[(3, "#000000", 0, 0)])

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#3 Post by bellice »

Well, the good news is, I no longer get an error, so thanks for that! Figures it'd be just a stupid oversight on my part. :oops:

The bad news is that the picture still doesn't show up. It just doesn't appear. I tried changing the position by adding xalign and yalign values, but it didn't do anything. Maybe I just did it wrong, though?

Tried it with

Code: Select all

image=Image("mc", xalign=0.005, yalign=0.900),

User avatar
akemicchi
Veteran
Posts: 465
Joined: Mon Dec 31, 2007 11:22 pm
Projects: Magicians of Delphine, Panaderia: Ensaimada, SweetTooth!, XOXO Droplets
Deviantart: littlebabyshoes
Contact:

Re: Changing the side-image according to gender choice

#4 Post by akemicchi »

If you're going to change positions, you have to do it in the screen say label in screens.rpy.

Code: Select all

    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0 #This is where you change the positions.
I think you'll also want to add 'side' to your images. Like:

Code: Select all

image side mc neutral = ConditionSwitch(#...)

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#5 Post by bellice »

Still nothing. Image just won't appear at all. :/

philat
Eileen-Class Veteran
Posts: 1926
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Changing the side-image according to gender choice

#6 Post by philat »

I didn't bother looking at your ConditionSwitch code before, but you don't need the Image() part. The following works.

Code: Select all

image mc neutral = ConditionSwitch(
    "gender == 'female'", "path1.png",
    "gender == 'male'", "path2.png"
    )

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Changing the side-image according to gender choice

#7 Post by xela »

philat wrote:I didn't bother looking at your ConditionSwitch code before, but you don't need the Image() part. The following works.

Code: Select all

image mc neutral = ConditionSwitch(
    "gender == 'female'", "path1.png",
    "gender == 'male'", "path2.png"
    )
This doesn't matter, Ren'Py will wrap the string in Image internally if you don't do it yourself. Your way doesn't change anything but it makes code look better (cleaner).

**The code works... your image should be there.
Like what we're doing? Support us at:
Image

philat
Eileen-Class Veteran
Posts: 1926
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Changing the side-image according to gender choice

#8 Post by philat »

Huh, didn't know that. Yeah, I gave the code a quick test run and knew it should work so I was grasping at straws. OP, try doing it over again in a clean project. Also, re-read the documentation -- it discusses when Renpy won't show a side image. You may have tagged the images incorrectly somehow.

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#9 Post by bellice »

Hmm...alright, then I'll make a new project and see how that goes.

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#10 Post by bellice »

Replicated it all in a new project, but there's still nothing. Alright, let's do this again, maybe I've just made some stupid mistake in my code. (By which I mean I've most definitely made some stupid mistake. Has to be, if it works for you guys.)

This is my script:

Code: Select all

#BACKGROUNDS

image hallway = "hallway.jpg"

# Declare characters used by this game.

define n = Character(None, what_color="#FFFFFF", what_outlines=[(3, "#000000", 0, 0)])
define guard = Character("Guard", who_ypos=-23, who_xpos=230, who_font="ui/Arsenal-Regular.otf", who_outlines=[(3, "#000000", 0, 0)], what_ypos=-30, what_xpos=200, what_color="#FFFFFF", what_outlines=[(3, "#000000", 0, 0)])
define l = Character("Lieutenant Bishop", who_ypos=-23, who_xpos=230, who_font="ui/Arsenal-Regular.otf", who_outlines=[(3, "#000000", 0, 0)], what_ypos=-30, what_xpos=200, what_color="#FFFFFF", what_outlines=[(3, "#000000", 0, 0)])

init:

    
    $ mc = Character("Jordan", 
        who_ypos=-23,
        who_xpos=230,
        who_font="ui/Arsenal-Regular.otf",
        who_outlines=[(3, "#000000", 0, 0)],
        image=Image("mc", xalign=0.005, yalign=0.900),
        what_ypos=-30,
        what_xpos=200,
        what_color="#FFFFFF",
        what_outlines=[(3, "#000000", 0, 0)])
        
        
        
        


# The game starts here.
label start:
    
    $ gender = "female" #default needs to be present
    
    
    
    scene hallway with dissolve

    n "The shackles bite painfully into my skin."
    n "They are just a tad too tight to be comfortable, no doubt on purpose."
    n "The two men walking on either side of me do so silently, their eyes stubbornly focused in front of them and their expressions grim."
    n "I assume they're male, anyway."
    n "Can't be too sure when it comes to other civilisations, especially in this backwater quadrant."
    n "I test my cuffs, trying to wiggle out of them."
    n "No dice."
    guard "You won't be able to escape these. They're reinforced titanium, uhm..."
    n "Obviously they're not too sure about our gender conventions, either."
    
    menu:
        "Ma'am.":
            $ gender = 'female'
            "Ma'am. I'm female."
            guard "Very well, Ma'am. I'd advise you to keep your hands still. You'll hurt yourself otherwise."
            
        "Sir.":
            $ gender = 'male'
            "Sir. I'm male."
            guard "Very well, Sir. I'd advice you to keep your hands still. You'll hurt yourself otherwise."
            
    mc neutral "You're surprisingly polite, considering you've just arrested us for murder."
    n "Somewhere behind me, there's a groan."
    l "Your sense of tact is as immaculate as always."
    mc annoyed "Just wait till I shove my tact right up your-"
    "The guard clears his throat."
    guard "It is customary in our society to treat prisoners with respect, no matter their crime."
    mc neutral "So you're not gonna throw us in a cell to starve?"
    guard "No. We do not stoop to your level."
    mc angry "My level? You listen here, twerp, I-"
    l "What WILL you do with us?"
    n "Sure, just interrupt me."
    n "Asshole."
    
            

    return
This is the relevant bit from my screens.rpy (unless there's more relevant bits I missed):

Code: Select all

    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage("mc") xalign 0.005 yalign 0.935
And this is my xLiveComposite:

Code: Select all

init-1:

    image side mc = "fmc_neutral.png"
    
# --------------------------

    image side mc neutral = ConditionSwitch(
        "gender == 'female' ", Image ("fmc_neutral.png"),
        "gender == 'male' ", Image ("mmc_neutral.png"),
        "True", Image ("fmc_neutral.png"),
        )
    
    image side mc annoyed = ConditionSwitch(
        "gender == 'female' ", Image ("fmc_annoyed.png"),
        "gender == 'male' ", Image ("mmc_annoyed.png"),
        "True", Image ("fmc_annoyed.png"),
        )
    
    image side mc pleased = ConditionSwitch(
        "gender == 'female' ", Image ("fmc_pleased.png"),
        "gender == 'male' ", Image ("mmc_pleased.png"),
        "True", Image ("fmc_pleased.png"),
        )
    
    image side mc angry = ConditionSwitch(
        "gender == 'female' ", Image ("fmc_angry.png"),
        "gender == 'male' ", Image ("mmc_angry.png"),
        "True", Image ("fmc_angry.png"),
        )
No error, just no side image whatsoever. The images are directly in the game directory. I also checked the whole thing with Lint and it gave me this:

Code: Select all

Ren'Py 6.14.1.366 lint report, generated at: Sat Jan 03 14:38:38 2015

Full traceback:
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\bootstrap.py", line 228, in bootstrap
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\main.py", line 317, in main
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\arguments.py", line 223, in post_init
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\lint.py", line 544, in lint
  File "C:\Users\Kniggi\Games\renpy-6.14.1-sdk\renpy\lint.py", line 360, in check_say
TypeError: sequence item 0: expected string, Image found

After initialization, but before game start.
TypeError: sequence item 0: expected string, Image found

philat
Eileen-Class Veteran
Posts: 1926
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Changing the side-image according to gender choice

#11 Post by philat »

It's the image=Image("mc") part. Change that to image="mc" like in my previous post.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Changing the side-image according to gender choice

#12 Post by xela »

Yeah, that should be it.

image is prolly not the best name for this argument... it can be a bit confusing.
Like what we're doing? Support us at:
Image

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#13 Post by bellice »

Tried that already when you posted it, but the game still plays the same.
I went over it with Lint again, though, and now it's giving me this:

Code: Select all

Ren'Py 6.14.1.366 lint report, generated at: Sun Jan 04 12:33:08 2015

game\script.rpy:67 Could not find image (mc neutral) corresponding to attributes on say statement.

game\script.rpy:70 Could not find image (mc annoyed) corresponding to attributes on say statement.

game\script.rpy:73 Could not find image (mc neutral) corresponding to attributes on say statement.

game\script.rpy:75 Could not find image (mc angry) corresponding to attributes on say statement.


Statistics:

The game contains 25 screens of dialogue.
These screens contain a total of 226 words,
for an average of 9.0 words per screen.
The game contains 1 menus.

Remember to set config.developer to False before releasing.

Lint is not a substitute for thorough testing. Remember to update Ren'Py
before releasing. New releases fix bugs and improve compatibility.
So there probably is something wrong with the tagging, but I can't for the life of me figure out what it is. I swear to god, me trying to code is like a pig trying to fly.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Changing the side-image according to gender choice

#14 Post by xela »

Code: Select all

add SideImage("mc") xalign 0.005 yalign 0.935
....... seriously, why do you keep doing weird stuff to Ren'Py? Is it a fetish? :D

There is a perfect, clear guide in the link philat provided, it should provide you with a set of flawless instructions. Stop doing kinky stuff. You can do it with SideImage("mc") as well but than you're declared your images wrong.

Just use default SideImage(), get it to display correctly and then mess with it.
Like what we're doing? Support us at:
Image

User avatar
bellice
Veteran
Posts: 259
Joined: Mon Jun 22, 2009 12:12 pm
Location: Germany, Bavaria
Contact:

Re: Changing the side-image according to gender choice

#15 Post by bellice »

xela wrote:

Code: Select all

add SideImage("mc") xalign 0.005 yalign 0.935
....... seriously, why do you keep doing weird stuff to Ren'Py? Is it a fetish? :D

There is a perfect, clear guide in the link philat provided, it should provide you with a set of flawless instructions. Stop doing kinky stuff. You can do it with SideImage("mc") as well but than you're declared your images wrong.

Just use default SideImage(), get it to display correctly and then mess with it.
Hey, no kink-shaming.

I tried to follow instructions! And then it didn't work and I tried to combine them with another set of instructions and then it still didn't do anything and then I panicked and then there was a lot of messing around without really understanding anything (because all that talk about tagging and stuff just makes my brain go stupid) and in the end I was so confused, I couldn't even remember what I had and hadn't tried.

In this case, I thought I had to let renpy know what the side image was. (I did look at the documentation, but I couldn't really find the important parts in it. I kept looking through it like this: :?: )

Buuuut it works now!
And I'd like to think I learned something along the way. So thanks you guys - all of you - for taking the time to help me, as stupid as I can get when it comes to coding. :oops:

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]