How to make a side portrait change depending on variables

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
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

How to make a side portrait change depending on variables

#1 Post by jingleriot »

I have my game set that you can select your appearance, using the livecomposite codes. I want to know if it's possible and how I would go about making the side image portrait change according to those variables.

Code: Select all

init python:

    def draw_character(st, at): 
        return LiveComposite(
            (670, 670), 
            (0, 0), "character/race/blank.png",
            (0, 0), ConditionSwitch(
            "race == 'mand-f'", "character/race/mand.png", 
            "race == 'mand-m'", "character/race/mand2.png", 
            "race == 'orc-f'", "character/race/orc.png",
            "race == 'orc-m'", "character/race/orc2.png",
            "race == 'beh-f'", "character/race/beh.png",
            "race == 'beh-m'", "character/race/beh2.png",
            )
            ),.1
            
init:
    image character = DynamicDisplayable(draw_character)



I tried this:

Code: Select all

define mc = Character("[mc]", image="mc")

Code: Select all

if race == "mand-f":
    image side mc = "images/manf.png"
elif race == "orc-f":
    image side mc = "images/orcf.png"
elif race == "beh-f":
    image side mc = "images/behf.png"
elif race == "orc-m":
    image side mc = "images/orcm.png"
elif race == "beh-m":
    image side mc = "images/behm.png"
else:
    image side mc = "images/manm.png"
but no image displays when the character "MC" talks. There's also no error, which makes me believe it IS finding all the files and variables just fine, but not displaying them. I feel like I'm missing something obvious and can't figure out what it is. Help is appreciated!

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: How to make a side portrait change depending on variables

#2 Post by Empish »

Looks like you already know how to do ConditionSwitches, so I'd recommend that approach.

Code: Select all

image side mc = ConditionSwitch("race == 'mand-f'", "manf.png",
"race == 'orc-f'", "orcf.png",
"race == 'beh-f'", "behf.png",
etc)

User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Re: How to make a side portrait change depending on variables

#3 Post by jingleriot »

ahhhhhhhhhhhhhhh okay, thank you so much! I'm gonna try this now!

User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Re: How to make a side portrait change depending on variables

#4 Post by jingleriot »

Unfortunately it was the same problem. No errors in the script, but also none of the images show up. I also tried adding the "images/" in front of mand-f.png (images/file.png) to see if that would make a difference. Still nothing. So I tried renaming the image tag to something other than mc and tried mmm, still nothing. I didn't think that would do anything, but I did genuinely think your idea was going to work. :/ Thank you for the help, though.

Edit:
I found out that the conditionswitch code is apparently outdated. I've unfortunately not found anything that sounds remotely like what I'm trying to do, so I'm still messing with code. I've tried several things, including attempting to tweak the code involving the conditionswitch as well as using the if/elif/else codes to no avail. I'm wondering if it's possible to have the image be something like

define mc = Character("[mc]", image="$race == orc") ? I'm not exactly sure what I'm trying to ask but I hope it's properly conveyed.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to make a side portrait change depending on variables

#5 Post by Remix »

I'm pretty sure LiveComposite supports undeclared DynamicImage components (or it can certainly use them if declared), so I suggest a bit of renaming and simplification...

Code: Select all

init python:

    def draw_character(st, at): 
        return LiveComposite(
            (670, 670), 
            (0, 0), "character/race/blank.png",
            (0, 0), DynamicImage( "character/race/[race].png" ) # you *should* be able to just use "character/race/[race].png" as below
            ),.1
         
image character = DynamicDisplayable(draw_character)
#
# or simply
#
image character2 = LiveComposite(
            (670, 670), 
            (0, 0), "character/race/blank.png",
            (0, 0), "character/race/[race].png"
            ),.1
Just make sure the 'race' variable holds values that reference the images, e.g.
race == 'mand-f'" >> "character/race/mand.png" (either rename image "character/race/mand-f.png" or the variable value to "mand") etc
Frameworks & Scriptlets:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to make a side portrait change depending on variables

#6 Post by Remix »

A few sub-notes:

For a side image you need to define the image as a side image... I think it is "image side character2 = ..."
Character parameter image defines a tag to use Character( "[mc]", image="character2" ) sets it to use character2 if I recall

I've not dabbled much with those yet though, perhaps someone else can help further.

To test the LiveComposite works, maybe:

Code: Select all

default race = "mand-f" # you will always want a default

label start:
    show character2
    "."
    $ race = "mand-m"
    ".."
Once that works, then explore using side images
Frameworks & Scriptlets:

User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Re: How to make a side portrait change depending on variables

#7 Post by jingleriot »

Hellooo~ Thank you for responding! I think I've already done all of that, and actually prefer the clunkier version of the code for my own sanity. Unless it will directly effect my ability to display side images, I'm not sure this is the help I was asking for. Unless I am misunderstanding what you are saying, which is also quite likely... ahhh.

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: How to make a side portrait change depending on variables

#8 Post by Empish »

When renpy can't find a side image to match what it's looking for it'll display nothing instead of giving you an error, so that's gotta be your problem. But Remix's stuff is pretty solid, it will work for both normal images and side images too.

Can you post what state your code is in now?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to make a side portrait change depending on variables

#9 Post by Remix »

The bit in the docs that best describes it is Side Images including mention of the caveat that Ren'py will show nothing if there is ambiguity in the image lookup process.
Frameworks & Scriptlets:

User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Re: How to make a side portrait change depending on variables

#10 Post by jingleriot »

I put in exactly what Remix said (with slight alterations so it can locate the files), but it keeps coming back with an error about character2

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/character_script.rpy", line 14, in script
image side character2 = LiveComposite(
Exception: Not a displayable: (<Fixed at 63ef410>, 0.1)

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

Full traceback:
File "game/character_script.rpy", line 14, in script
image side character2 = LiveComposite(
File "C:\Users\Jimbles\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 925, in execute
renpy.exports.image(self.imgname, img)
File "C:\Users\Jimbles\Desktop\renpy-6.99.12.4-sdk\renpy\exports.py", line 353, in image
d = renpy.easy.displayable(d)
File "C:\Users\Jimbles\Desktop\renpy-6.99.12.4-sdk\renpy\easy.py", line 108, in displayable
raise Exception("Not a displayable: %r" % (d,))
Exception: Not a displayable: (<Fixed at 63ef410>, 0.1)

Windows-8-6.2.9200
Ren'Py 6.99.13.2919
Monster Party 1.0

here's the code:

Code: Select all

init python:

    def draw_character(st, at): 
        return LiveComposite(
            (670, 670), 
            (0, 0), "character/race/blank.png",
            (0, 0), DynamicImage( "character/race/[race].png" ) # you *should* be able to just use "character/race/[race].png" as below
            ),.1
         
image character = DynamicDisplayable(draw_character)
#
# or simply
#
image side character2 = LiveComposite(
            (670, 670), 
            (0, 0), "character/race/blank.png",
            (0, 0), "character/race/side_images/[race].png"
            ),.1

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.

#characters
define mc = Character("[mc]", image="character2")

#portraits
image w = "images/character/witch.png"

#side portraits
image side w = "images/asheside.png"


# The game starts here.

default race = "mand-f" # you will always want a default

label start:
    show character2
    "."
    $ race = "mand-m"
    ".."
p.s., in case it's relevant, I do have the composite characters in a separate .rpy file labelled "character_script.rpy"

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: How to make a side portrait change depending on variables

#11 Post by Empish »

It looks like (at least as far as I can tell) it's not wanting to do the dynamic image straight-up for you. You can always try changing character2 to this

Code: Select all

image race_face = "character/race/side_images/[race].png"

image character2 = LiveComposite(
    (670,670),
    (0,0), "character/race/blank.png",
    (0,0), "race_face"
    )

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to make a side portrait change depending on variables

#12 Post by Remix »

... this works (for side image with variables changing parts) ...

Code: Select all

define e = Character("Eileen", image="eileen")

default bikini_top = "1"
default bikini_lower = "1"

image side eileen = LiveComposite(
            (129, 563), 
            (0, 0), "images/brunette.bikini.pink.head.png",
            (0, 162), "images/brunette.bikini.pink.top.[bikini_top].png",
            (0, 231), "images/brunette.bikini.pink.middle.png",
            (0, 281), "images/brunette.bikini.pink.panties.[bikini_lower].png",
            (0, 324), "images/brunette.bikini.pink.legs.png"
            )

label start:
    # show side eileen # no need this for side images, those are automatic
    e "start"
    $ bikini_top = "2"
    e "middle"
    $ bikini_lower = "3"
    e "end"
Hopefully it can get you heading in the right direction...
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]