Issue with using call labels

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
mold.FF
Newbie
Posts: 21
Joined: Fri Jun 30, 2017 5:04 am
Projects: Tiny Bunny, Crown of Leaves, Army Gals: Poker DLC, Galaxy Girls: Poker DLC
Skype: irzen89
Contact:

Issue with using call labels

#1 Post by mold.FF »

Hi everyone, I'm working on a novel and there are couple scene where player talks to 4 characters simultaniously. They speaks in turns like in regular dialogue, the issue is to show what character is speaking right now. The thing is that they all wear masks.
We decided to do it like that - speaking character steps forward, and then steps back when he done speaking his line. Also usualy they change their posture when they step in.
The direct solution how to make is that:

Code: Select all

show Tom 1:
    align (.5, 1.)
    xoffset tom_xoffset
    zoom 1.0
    parallel:
        linear .3 zoom 1.05
    parallel:
        "Tom 2" with Dissolve(.3)
tom "Hi!"
show Tom 2:
    align (.5, 1.)
    xoffset tom_xoffset
    zoom 1.05
    parallel:
        linear .3 zoom 1.0
    parallel:
        "Tom 1" with Dissolve(.3)
It's very bothersome to write all that code for each line, so I made a labels that do all that:

Code: Select all

define tom_xoffset = -300
define step_in = 1.05
define step_out = 1.00
default tom_sprite_cur = "Tom 1"
default tom_zoom_cur = step_out
transform tom_pos:
    align (.5, 1.)
    xoffset tom_xoffset
label tom_upd(sprite_new = None, zoom_new = None):
    hide Tom
    hide tom_sprite_cur

    if sprite_new is None:
        $ sprite_new = tom_sprite_cur
    if zoom_new is None:
        $ zoom_new = tom_zoom_cur

    show expression tom_sprite_cur:
        tom_pos
        parallel:
            zoom tom_zoom_cur
            linear .3 zoom zoom_new
        parallel:
            sprite_new with Dissolve(.2)

    pause .01
    $ tom_zoom_cur = zoom_new
    $ tom_sprite_cur = sprite_new
    return
Repeated for each character and dialog starts looking like that:

Code: Select all

call tom_upd("Tom 2", step_in)
tom "Hi!"
call tom_upd("Tom 1", step_out)

call bob_upd("Bob 2", step_in)
bob "Hi!"
call bob_upd("Bob 1", step_out)
It works fine, except when I try to rollback, I'm getting an error that variable zoom_new is not defined. Making a default zoom_new = 1.0 statement doesn't solve the issue fundamentaly.
The good thing that novel I'm working on will have a disabled rollback feature for various reasons so player won't get this error.
Still this error and a neccessity to add pause .01 statement before I update character related variables for unknown for me reasons demonstrates that I don't truly understand the way Renpy works and what best solution should be here.

So, the questions are
1. Why an error with zoom_new happens
2. How it could be fixed
3. What is the better solution for this situation

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Issue with using call labels

#2 Post by zmook »

I think you can do what you want more easily by defining a few transitions and transforms:

Code: Select all

define step_time = 0.3
define step_in = 1.05

define dslv3 = Dissolve(step_time)
transform move_forward:
        linear step_time  zoom step_in
transform move_back:
        linear step_time  zoom 1.0
    
label start:

    show Tom 1 at center    # position where you like
    "this is Tom"
    show Tom 2 at move_forward with dslv3
    tom "Hi!"
    show Tom 1 at move_back with dslv3
    "tom has shut up"
    
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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: Issue with using call labels

#3 Post by Remix »

If you are using tags for your image names and your Character definitions specify their image="their tag" property, you could automate the lot...

Code: Select all

init python:

    def pop_character(trans, st, at, tag=None):

        ## Check get_say_image_tag() and adjust up if tag matches else down
        adjust = 0.005 if tag == renpy.get_say_image_tag() else -0.005

        ## The 1.1 here is the max zoom, adjust as needed
        trans.zoom = min(1.1, max(1.0, trans.zoom + adjust))

        return 0.0

transform pop_char(tag=None):
    function renpy.curry(pop_character)(tag=tag)

image eileen = Solid("#F00", xysize=(200, 400))
image eileen happy = Solid("#D76", xysize=(200, 400))
image lucy = Solid("#F4F", xysize=(200, 400))

define e = Character("Eileen", image="eileen")
define l = Character("Lucy", image="lucy")

label start:

    ## at transform (with specified tag reference) and positional data in block
    show eileen at pop_char("eileen"):
        anchor (0.5, 1.0)
        pos (150, 1.0)

    show lucy at pop_char("lucy"):
        anchor (0.5, 1.0)
        pos (650, 1.0)

    # get_say_image_tag is None
    "Neither"

    # Now get_say_image_tag is "eileen"
    # eileen image now zooming larger
    e "Me"

    # get_say_image_tag now "lucy"
    # lucy image now zooming larger AND eileen shrinking 
    l "Me"

    # still works when showing "eileen happy" as the "eileen" tag is present
    e happy "Me"

    l "Me"
    
    pause
    
    return
Frameworks & Scriptlets:

mold.FF
Newbie
Posts: 21
Joined: Fri Jun 30, 2017 5:04 am
Projects: Tiny Bunny, Crown of Leaves, Army Gals: Poker DLC, Galaxy Girls: Poker DLC
Skype: irzen89
Contact:

Re: Issue with using call labels

#4 Post by mold.FF »

zmook, Remix, your ideas looks awesome. Thanks. I'll dig in that way.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot]