Question on labels screens and flow control

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.
Message
Author
terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Question on labels screens and flow control

#1 Post by terrordoll »

I'm making some decent progress on my game but I seem to run into problems consistently when bouncing between screens. There is something about the flow of things I'm just wrapping my head around. If someone could explain this to me i'd be hugely grateful.

Here's what I'm trying to do. I have a map screen with locations you can select. When you select a location it should confirm your selection if certain requirements are met. Right now its based on the time period you are in (I've chopped up and integrated the dating engine). If you don't meet the requirements a notify screen informs you of the reason why. Selecting "no" on the confirm or failing to meet the requirements should keep you on the map screen. If you select yes and meet the requirements, you are transferred to an event which handles the rest.

I'd really appreciate if someone could look at my code and then explain to me what I'm doing wrong and any theory I'm missing. I feel like I'm just not getting the proper way to do all of this and I've been all through the documentation.

Here is the code I have so far. It "almost" works but it feels janky. Right now the biggest issue is the notify doesn't show over my map. I do see it though If I back out of it into another location so I know it's there.

Code: Select all

label map:
    scene map_ground
    call screen mapscreen
    
label location_cove:
    if period == "morning" or period == "afternoon":
        $ act = "visit_cove"
        call screen confirm("Visit the cove?", Jump('doevent'), Jump('map'))
    else:
        show screen notify("Its a little late to visit the cove. I don't want to get stuck outside after dark.")
        jump map
here is the screen. The ('location_cove') button is the one I'm trying to get to work right now.

Code: Select all

screen mapscreen():
    frame:
        xsize 1920
        ysize 1080
        xpos 0
        ypos 0
        background "map_ground.png"
        
        imagebutton auto "gui/map_icon_%s.png" action Hide('map') xpos 0 ypos 0 focus_mask True
        imagebutton auto "gui/map_camp_%s.png" action Jump('LocationCamp') xpos 1125 ypos 675 focus_mask True
        imagebutton auto "gui/map_mermaid_%s.png" action Jump('location_cove') xpos 1495 ypos 549 focus_mask True
Any direct help would be great but theory would be even better. I'm a C# programmer and it's driving me crazy that I can't seem to grasp how this is all supposed to fit together.

Thanks!

*EDIT-
In case it matters, here is the code that launches the map screen:

Code: Select all

label TentInterior:
    #What image should we display based on time of day?
    if period == "morning":
        scene bg tent
        
    elif period == "afternoon":
        scene bg tent
    elif period == "evening":
        scene bg tent
    elif period == "night":
        scene bg tent
    
    if tent_first == False:
        hide screen gameui
        show mc_base at right
        amber "Here is my tent"
        hide mc_base
        $ tent_first = True
    
    show screen gameui
    call screen campinterior

screen campinterior():
    zorder 90
    frame:
        xsize 1920
        ysize 1080
        xpos 0
        ypos 0
        background None
        
        imagebutton auto "tent_map_%s.png" action Jump('map') xpos 106 ypos 2 focus_mask True
Last edited by terrordoll on Fri May 12, 2017 4:47 pm, edited 1 time in total.

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Question on labels screens and flow control

#2 Post by Scribbles »

under your map screen... you could add an if statement to determine if the area was unlocked yet (however you would do it, i just used something basic)

Code: Select all

if cove_unlocked:
    imagebutton auto "gui/map_mermaid_%s.png" action Jump('location_cove') xpos 1495 ypos 549 focus_mask True
else:
    #image button that does the notification you want and nothing else?
would that help?
Image - Image -Image

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#3 Post by terrordoll »

Scribbles wrote:under your map screen... you could add an if statement to determine if the area was unlocked yet (however you would do it, i just used something basic)

Code: Select all

if cove_unlocked:
    imagebutton auto "gui/map_mermaid_%s.png" action Jump('location_cove') xpos 1495 ypos 549 focus_mask True
else:
    #image button that does the notification you want and nothing else?
would that help?

It might help, but i'm starting to think my problem is more foundational than syntax. I have a feeling that all this jumping around and passing control isn't right. It's definitely not what I'd do in C#. I'm wondering if perhaps I should be handling all of this checking and gating with function calls on the buttons instead.

Thanks for the reply!

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Question on labels screens and flow control

#4 Post by Saltome »

When I go about making complicated screens I just go like this:

Code: Select all

screen Location_Screen:
    vbox at center:
        frame:
            #at right
            maximum config.screen_width,config.screen_height/3
            vbox:
                text "Actions:" align .5,.5
                viewport:
                    mousewheel True
                    draggable True
                    vbox:
                        for a in Locations[game.player_loc].get_action_list():
                            textbutton Actions[a].name:
                                action Hide("Locations_Preview_Window"), Return(ACTION_CALL_MAPACTION(a))
                                xfill True
label Location_Interface:
    $ game.quit = False
    show screen Location_Screen()
    show expression Images[Locations[game.player_loc].IMGID]
    while not game.quit:
        
        $ r = ui.interact()
        if isinstance(r, ACTION_CALL_MAPACTION):
            hide screen Location_Screen
#            call expression "MapAction_{:d}".format(r.id)
#            call MapAction(r.id)#expression "MapAction_{:d}".format(r.id)
            $ ID=r.id
            if ID==1:
                call Event_0 from _call_Event_0
            elif ID==0:
                $ l = Locations[game.player_loc].traits[0].value
                "A generic [l]"
            elif ID==2:
                #$Locations[game.player_loc].traits.remove(Locations[game.player_loc].traits[0])
                call Event_1 from _call_Event_1_1
            elif ID==3:
                $ Locations[game.player_loc].traits.remove(Locations[game.player_loc].traits[0])
                call Event_2 from _call_Event_2
            elif ID==4:
                call Navigation_Interface from _call_Navigation_Interface
            elif ID == 5:
                call Event_3 from _call_Event_3
            elif ID == 6:
                call Event_OrderExploration from _call_Event_OrderExploration
            elif ID == 7:
                call Event_OrderEstablishSettlement from _call_Event_OrderEstablishSettlement
            elif ID == 8:
                call Feed_Interface from _call_Feed_Interface
            show screen Location_Screen()
        if game.get_player().hastraitname("Starved to death"):
            $ game.kill_actor(game.get_player().ID, "Starved to death")
            $ game.quit = True
    hide screen Location_Screen
    return
Granted I really need to update my system, this is my general approach.
I jump to a label, run a loop inside it, catching the renpy.interact events from the screen then processing them in the label and when I'm done I just break the loop.
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#5 Post by terrordoll »

Saltome,

Thanks for the reply I appreciate it.

I like the idea of handling the logic within a single label and this would give me most of that. While its a workable solution it feels a little like I'm working against the system though. What I'm doing (gating a action with a few different conditions an confirmations), doesn't seem like it should be very complicated. This is why I feel like my approach is wrong. The things I need appear to be in place. A label, a call screen, notify and confirm screens etc. They just don't seem to play nice together. Actually it's not really even those elements so much as it it the passing of control between them which your loop does handle.

I was thinking that part of my problem is trying to pass off control to a new label or screen too often. I wonder if maybe handling button state and actions inside a function would be the better way to go? That way I could evaluate and run code without having to jump to a label to do it. Im not sure if that's really going to help me.

So thank ou very much for taking the time to reply. My hope is to figure out how to do this with the basic tools I have as an exercise i understanding. If I can't figure it out I'll likely use your method as it would solve the problem.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Question on labels screens and flow control

#6 Post by trooper6 »

There is a lot going on in your code that I'd do differently...but I can't get into it all right now due to grading.
However, just a quick thing about your mapscreen:

Code: Select all

imagebutton auto "gui/map_temple_%s.png" action [Hide('map'), Jump('location_temple')] xpos 1304 ypos 498 focus_mask True
Screen actions hide screens, so that should be Hide('mapscreen') ... you can't Hide a label, only a screen.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#7 Post by terrordoll »

trooper6 wrote:There is a lot going on in your code that I'd do differently...but I can't get into it all right now due to grading.
However, just a quick thing about your mapscreen:

Code: Select all

imagebutton auto "gui/map_temple_%s.png" action [Hide('map'), Jump('location_temple')] xpos 1304 ypos 498 focus_mask True
Screen actions hide screens, so that should be Hide('mapscreen') ... you can't Hide a label, only a screen.
Ya that's my bad. This used to be set up differently and that is an artifact. I've removed it from my OP. I'm trying to get this all figured out between my camp and cove locations. Once I have it nailed down I'll roll it out to my other locations such as the Temple.

I appreciate your time and welcome any other advice or criticisms you have. I'm interested in how you might set this all up, if you have a moment at some point.

Thanks again!

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Question on labels screens and flow control

#8 Post by trooper6 »

I'm in the end of the semester grading crunch for the next few days, but when I get some time I'll look more deeply into it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#9 Post by terrordoll »

I'm reading up on functions and diving into python in the mean time. Thanks again for all your time and help!

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#10 Post by terrordoll »

Schedule still crazy Trooper6?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Question on labels screens and flow control

#11 Post by trooper6 »

Schedule still very crazy...graduation is on Sunday, but I had a bit of time to play around with the concept. Here is how I'd do it. This is based off of an earlier map test I made. It is adapted to fit your description, but it still has some things from my original work (tracking how many times you went to any given location for example).

I'm posting the code below but also attaching the project so you can see how it works yourself.

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 e = Character("Eileen")

#My images are large, so I'm scaling my images so they'll fit my game
image sample_map = im.FactorScale("images/Leeuwarden1664.jpg", 0.6)
image loc_hover = im.Scale("images/event_hover.png", 150, 150)
image loc_idle = im.Scale("images/event_idle.png", 150, 150)
image khaki = Solid("#f0e68c")

#Here I am initializing two locations that can be visited and the all_locs list 
default camp = Location("Camp", 450, 100, ["afternoon", "evening"], "camp", 
    "Its a little early to visit the camp. No one will be there.")
default cove = Location("Cove", 500, 250, ["morning", "afternoon"], 
    "cove", "Its a little late to visit the cove. I don't want to get stuck outside after dark.")
default all_locs = [camp, cove]
default time_of_day = "morning"

init python:
    class Location(object):
        def __init__(self, name, xp, yp, avail, dest, noavail):
            self.name = name
            self.xp = xp
            self.yp = yp
            self.available = avail
            self.dest = dest
            self.noavail = noavail
            self.visits = 0
            

    def visit(loc):
        global time_of_day
        if time_of_day in loc.available:
            loc.visits +=1
            renpy.jump(loc.dest)
            renpy.return_statement()
        else:
            renpy.notify(loc.noavail)

screen mapscreen():
    add "sample_map" xalign 0.5
    for loc in all_locs:
        fixed:
            xpos loc.xp
            ypos loc.yp  
            fit_first True
            imagebutton:
                hover "loc_hover"
                idle "loc_idle"
                align (0.5,0.5)
                focus_mask True
                activate_sound "click.wav"
                action Function(visit, loc)
            text loc.name align(0.5,0.5)
    textbutton "Exit" action Return() xalign 0.82 yalign 0.85
    
label start:
    scene khaki
    "Your game starts here."
    "Now, let's travel."
    jump navigation

label navigation:
    call screen mapscreen()
    "You've finished your travels. Game Over."
    return
    
label camp:
    "Blah Blah Camp"
    "How many visits: [all_locs[0].visits]"
    jump navigation
    "You should never reach this line."
    return
    
label cove:
    "Blah Blah Cove"
    "How many visits: [all_locs[1].visits]"
    jump navigation
    "You should never reach this line."
    return
    
Attachments
ZZ Terror Map Example.zip
(1.19 MiB) Downloaded 52 times
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

terrordoll
Regular
Posts: 46
Joined: Tue Apr 11, 2017 11:57 am
Contact:

Re: Question on labels screens and flow control

#12 Post by terrordoll »

Trooper6 this is amazing!

I understand all of it. The example of a python class and a function is also a huge help. I mentioned earlier I'm a C# programmer but I haven't had much time to dig into python yet. Just seeing simple syntax examples is most of what I need.

This is the sort of thing I'd love to see in the documentation. More common use case topics. Scrubbing through the docs right now is painful when you aren't sure exactly what you are looking for.

Thanks again Trooper, this has been really helpful.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Question on labels screens and flow control

#13 Post by trooper6 »

Glad it was helpful.

I think the problem with having this be in the documentation is:
-PyTom spends most of his time working on the engine itself rather than the documentation, so all the time he spends on documentation is not spent on improving the engine.
-I think maybe other people can do documentation changes through GitHub? Maybe? But I don't know how exactly that process works.
-There is more than one way to do things, and I don't think PyTom finds specific decontextualized examples to be all that useful in the documentation...at least I seem to recall him writing that once.
-The Cookbook section tends to be where you can find examples of things in context...so I'd recommend looking there...or in some of the games that have been left unarchived.

Anyway, I like being helpful!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Question on labels screens and flow control

#14 Post by PyTom »

Part of it is that since Ren'Py is a language an engine, the number of things you can do with it is kind of huge. And many of the examples would the purpose of the reference manual, which is to be the normative guide to what Ren'Py can do. Think of it kind of like learning to drive a car. One could certainly teach someone how to drive from Town A to Town B as a series of "press this pedal, turn this wheel, press this pedal". But the sort of documentation that goes on renpy.org is more about what the pedal and wheels do, and then we kind of trust you'll figure it out or someone can explain it.

Maybe painting is a similar process? One can teach about brushes, and color theory, and whatever - but at the end of the day, you have to put them together yourself to make a painting.

I am starting up a new series of articles that are far more tutorial today. Since I'm paying to have them edited, they'll be up on my patreon account - one of the things I can do with the resources that gives me. But there's always a kind of limitation there - the first article is on timed menus, but even there I make some assumptions on how things should operate.

The github process for making changes would be to fork Ren'Py on github, use the web interface to edit the files in sphinx/source/, save, and send me a pull request.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Question on labels screens and flow control

#15 Post by trooper6 »

PyTom wrote: The github process for making changes would be to fork Ren'Py on github, use the web interface to edit the files in sphinx/source/, save, and send me a pull request.
If I knew what "forking Ren'py on GitHub" meant, I'd look into adding some documentation...because it seems all I ever do is tell people to use default to declare their variables...and that really should be in the quickstart.

I'm subscribed to renpy on GitHub...but somehow I suspect that isn't the same thing as forking? Maybe a quick tutorial on how do to it could be good? Also for Mac users as well?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Bing [Bot]