How to make code stop in a certain scene

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
Vennnot
Newbie
Posts: 12
Joined: Mon Mar 19, 2018 4:48 pm
Contact:

How to make code stop in a certain scene

#1 Post by Vennnot » Tue Mar 09, 2021 5:41 pm

Hey everyone. I've been having trouble with the emma part of this code. It's intended behaviour is that you talk to her and return to the screen hallway 2 where she is still visible but the code is skipping to the hallway 1 scene and leaving her and chad's screen up. Not only that, but sometimes it goes even further back and sometimes the game just ends. I'm not sure what is happening. If anyone has any insights please let me know. It's driving me insane, i've wasted three hours on this.


This is my screens code:

Code: Select all

init:
    transform arrowSize:
        zoom 0.09

screen gotohallway1():
    imagebutton: #image that has a button attached to it
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [Hide("gotohallway1"), Hide("emmascreen"), Hide("chadscreen"), Jump("hallway1")]
        at arrowSize

screen gotohallway2():
    imagebutton:
        xalign 0.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [ Hide("gotohallway2"), Jump("hallway2")]
        at arrowSize

screen gotohallway3():
    imagebutton:
        xalign 0.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [ Hide("gotohallway2"), Jump("hallway2")]
        at arrowSize

screen emmascreen():
    imagebutton:
        xalign 0.85
        yalign 0.5
        idle "emmaIdle.png"
        hover "emmaHover.png"
        action Call("emmalabel")

screen chadscreen():
    imagebutton:
        xalign 0.691 #(1143, 374, 263, 271?????????)
        yalign 0.465
        idle "chadIdle.png"
        hover "chadHover.png"
        action If(renpy.get_screen("emmascreen"), Hide("emmascreen"), Show("emmascreen"))
and my main code:

Code: Select all

label intro:

    #python:
    $ playerName = renpy.input("What is your name?")
    $ playerName = playerName.strip() or "Robbie"



    scene intro
    "{cps=25}It's been a month since I dropped out of trade school and lost my scholarship.{/cps}"
    "{cps=25}I've been looking for an apartment and a job, and I finally found something.{/cps}"
    "{cps=25}I found a run down apartment in the boonies and a shitty job. It's a kick to the balls but I've come back to work here.{/cps}"
    "{cps=25} {b}Fucking embarrassing{/b}{/cps}{cps=2}...  {/cps}{cps=15}but I need the job.{/cps}"

    $ introDone = True

    call mondaymorning

label mondaymorning:

    scene principal_office

    show mc_tired at left with dissolve

    main "*sigh* What am I doing..."

    show principal_mad at right with dissolve

    pri "Are you even listening to me [playerName]?"

    hide principal_mad

    show principal_annoyed at right

    pri "[playerName] I hired you because I believe in second chances. Even though you dropped out, I'm giving you a chance to get your life back on track."

    main "Yeah I uh... I'm trying..."

    hide principal_annoyed

    show principal_compassion at right

    pri "..."

    pri "It'll be okay."

    main "..."

    pri "..."

    main "I'll get to it..."

    call hallway2
    
label mondaylate:

label mondayafternoon:

label emmalabel:

    if(emmaTalk == 0 and not emmaTalkNow):
        emm "Anon? Is that you?"

        main "Hey Emma, how you doing?"

        emm "Why are you wearing a Janitor's uniform?"

        $ emmaTalk += 1
        $ emmaTalkNow = True

        return

    elif(emmaTalk == 1 and not emmaTalkNow):

        emm "yo bro"

        return

    elif(emmaTalkNow):

        "I've already talked to Emma."

        return

window hide

$ renpy.pause(hard=True)

label chadlabel:

    window hide

    $ renpy.pause(hard=True)

label hallway2:

    scene hallway2

    show screen chadscreen

    show screen gotohallway1

    window hide

    $ renpy.pause(hard=True)

label hallway1:

    scene hallway1

    show screen gotohallway2

    window hide

    $ renpy.pause(hard=True)

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to make code stop in a certain scene

#2 Post by _ticlock_ » Tue Mar 09, 2021 6:43 pm

Hi, Vennnot,

About your problem: When you are at label hallway2, you are at line renpy.pause(hard=True). Thus, when you return from label emma you don't go to the start of label hallway2, but to the next line after renpy.pause(hard=True), which is hallway1.

PS: The construction you are using are quite hard to read and organize. You may encounter other problem, that you may spend time to figure out what is wrong. Instead of using many screen that have only one button, and showing them in label with pause for player to interact, consider to use one screen with all buttons(you can apply conditions whether to show a button or not) and call this screen. For example:

Code: Select all

screen hallway2():
    imagebutton: #go to hallway 1
        ...
    imagebutton: #chadscreen
        ...
    if condition_to_show_button:
        imagebutton: #emmascreen
        ...
        
label mondaymorning:
    ...
    #instead of call label hallway2, we call screen hallway2
    call screen hallway2

label emmalabel:
    ...
    call screen hallway2

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to make code stop in a certain scene

#3 Post by _ticlock_ » Wed Mar 10, 2021 12:31 am

Full example with screen per location:

Code: Select all

screen hallway1():
    add "hallway1.jpg" #background
    imagebutton: # Go to hallway 2
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [Hide("hallway1"), Show("hallway2")]
        at arrowSize

screen hallway2():
    default show_emma = True
    add "hallway2.jpg" #background
    imagebutton: # Go to hallway 1
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [Hide("hallway2"), Show("hallway1")]
        at arrowSize
    imagebutton: # chad
        xalign 0.691 
        yalign 0.465
        idle "chadIdle.png"
        hover "chadHover.png"
        action ToggleScreenVariable("show_emma")
    if show_emma:
        imagebutton: # emma
            xalign 0.85
            yalign 0.5
            idle "emmaIdle.png"
            hover "emmaHover.png"
            action Jump("emmalabel")
Then in your script:

Code: Select all

label mondaymorning:
    ...
    main "I'll get to it..."

    call screen hallway2
    

label emmalabel:

    if(emmaTalk == 0 and not emmaTalkNow):
        emm "Anon? Is that you?"

        main "Hey Emma, how you doing?"

        emm "Why are you wearing a Janitor's uniform?"

        $ emmaTalk += 1
        $ emmaTalkNow = True

    elif(emmaTalk == 1 and not emmaTalkNow):

        emm "yo bro"

    elif(emmaTalkNow):

        "I've already talked to Emma."

    call screen hallway2

Vennnot
Newbie
Posts: 12
Joined: Mon Mar 19, 2018 4:48 pm
Contact:

Re: How to make code stop in a certain scene

#4 Post by Vennnot » Wed Mar 10, 2021 3:18 am

Thank you so much! I just started to use Renpy this week so I'm fairly new. That solved most of my problems, the only problem now is that there is a small window when switching locations that it looks completely empty. I'm trying to make it so that when it switches from one area to the other there's no empty space (the checkered pattern). Right now i've been trying with dissolves and instant hides but I'm not sure. Should I just put it into the screen? Or is there a way to hide ALL scenes and sprites when I call hallway2

Code: Select all

label mondaymorning:

    scene principal_office

    show mc_tired at left with dissolve

    main "*sigh* What am I doing..."

    show principal_mad at right with dissolve

    pri "Are you even listening to me [playerName]?"

    hide principal_mad

    show principal_annoyed at right

    pri "[playerName] I hired you because I believe in second chances. Even though you dropped out, I'm giving you a chance to get your life back on track."

    main "Yeah I uh... I'm trying..."

    hide principal_annoyed

    show principal_compassion at right

    pri "..."

    pri "It'll be okay."

    main "..."

    pri "..."

    main "I'll get to it..."


    hide principal_compassion with dissolve
    hide mc_tired with dissolve
    hide principal_office
    call screen hallway2
    

Code: Select all

screen hallway2():
    add "hallway2.png" #background
    default show_emma = True
    imagebutton: # Go to hallway 1
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action [Hide("hallway2"), Show("hallway1")]
        at arrowSize
    imagebutton: # chad
        xalign 0.691
        yalign 0.465
        idle "chadIdle.png"
        hover "chadHover.png"
        action ToggleScreenVariable("show_emma")
    if show_emma:
        imagebutton: # emma
            xalign 0.85
            yalign 0.5
            idle "emmaIdle.png"
            hover "emmaHover.png"
            action Jump("emmalabel")
            

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to make code stop in a certain scene

#5 Post by _ticlock_ » Wed Mar 10, 2021 12:08 pm

Vennnot wrote:
Wed Mar 10, 2021 3:18 am
the only problem now is that there is a small window when switching locations that it looks completely empty. I'm trying to make it so that when it switches from one area to the other there's no empty space (the checkered pattern). Right now i've been trying with dissolves and instant hides but I'm not sure. Should I just put it into the screen? Or is there a way to hide ALL scenes and sprites when I call hallway2
Ok, to keep it simple with transitions. Remove background from the screens and put them in the label. And use Jump statement as actions:

Code: Select all

    imagebutton: # Go to hallway 2
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action Jump("hallway2")
        at arrowSize

screen hallway2():
    default show_emma = True
    add "hallway2.jpg" #background
    imagebutton: # Go to hallway 1
        xalign 1.0
        yalign 0.5
        idle "red_arrow.png"
        hover "red_arrow_hover.png"
        action Jump("hallway1")
        at arrowSize
    imagebutton: # chad
        xalign 0.691 
        yalign 0.465
        idle "chadIdle.png"
        hover "chadHover.png"
        action ToggleScreenVariable("show_emma")
    if show_emma:
        imagebutton: # emma
            xalign 0.85
            yalign 0.5
            idle "emmaIdle.png"
            hover "emmaHover.png"
            action Jump("emmalabel")

Code: Select all

label hallway1:
    scene hallway1 with dissolve                  # We put the background of the screen hallway1 in the label hallway1
    call screen hallway1
    jump hallway1                                       # A loop to go back to the start of the label. Right now it is not necessary, but may be useful later
label hallway2:
    scene hallway2 with dissolve
    call screen hallway2
    jump hallway2
And change call screen hallway to jump label hallway:

Code: Select all

label mondaymorning:
    ...
    jump hallway2
    
label emmalabel:
    ...
    jump hallway2
PS: scene statements are used to clear a layer from all images, sprites, and optionally to show a new image on that layer. https://www.renpy.org/doc/html/displayi ... -statement

Vennnot
Newbie
Posts: 12
Joined: Mon Mar 19, 2018 4:48 pm
Contact:

Re: How to make code stop in a certain scene

#6 Post by Vennnot » Wed Mar 10, 2021 2:17 pm

Emma disappears now when I click to talk to her. I would use this feature for some things but right now I don't want for things to disappear when I click on them. How do I avoid this? I did with my code what you did with yours. There are no errors and everything is smooth but this emma thing is bothering me so much.

Vennnot
Newbie
Posts: 12
Joined: Mon Mar 19, 2018 4:48 pm
Contact:

Re: How to make code stop in a certain scene

#7 Post by Vennnot » Wed Mar 10, 2021 2:21 pm

Oh it's because of the show_emma variable. Is there a way to toggle a screen without giving it a variable? Every time screen hallway2 runs it resets emmas status to the default. Can I contact this variable from script.py?

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to make code stop in a certain scene

#8 Post by _ticlock_ » Wed Mar 10, 2021 2:55 pm

Vennnot wrote:
Wed Mar 10, 2021 2:17 pm
Emma disappears now when I click to talk to her. I would use this feature for some things but right now I don't want for things to disappear when I click on them. How do I avoid this? I did with my code what you did with yours. There are no errors and everything is smooth but this emma thing is bothering me so much.
Right. Sorry, I forgot to mention, that you should show her again in the label emmalabel.

Code: Select all

label emmalabel:
    show emmaIdle:
        xalign 0.85
        yalign 0.5
This way you will have control over her sprite, and can easily change her expression or move her to the center:

Vennnot
Newbie
Posts: 12
Joined: Mon Mar 19, 2018 4:48 pm
Contact:

Re: How to make code stop in a certain scene

#9 Post by Vennnot » Wed Mar 10, 2021 3:01 pm

Thank you so much for your help, you'll be in the thanks for my game.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], khezo