Yes/No prompts

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
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Yes/No prompts

#1 Post by Nicckonator »

Hey all :)
Just wanted to know if there was a way to separate / disable certain yes/no prompts.
For example: i want to keep my 'quit' yes/no prompt, but remove my 'are you sure you want to save' yes/no prompt and remove my 'loading will lose unsaved progress are you sure you want to do this?' yes/no prompt.

I'm looking to either remove those or separate them in the code so i can alter the x and y positions for all 3 seperately, because right now all 3 of them use my custom confirm overlay in different sizes and locations for some reason.

Code: Select all

screen confirm(message, yes_action, no_action):

    ## Ensure other screens do not get input while this screen is displayed.
    modal True

    zorder 200

    style_prefix "confirm"

    add "gui/overlay/confirm.png"

    frame:

        vbox:
            xalign .5
            yalign .5
            spacing 45

            label _(message):
                style "confirm_prompt"
                xalign 0.5
                if message == "Are you sure you want to quit?":
                    text_color "#0000"
                else:
                    text_color "#0000"


            hbox:
                box_wrap True

                vbox:

                    textbutton _("Yes") action yes_action
                    xpos 105
                    ypos -38

                vbox:

                    textbutton _("No") action no_action
                    xpos 105
                    ypos -38
                    
update: managed to remove the text itself, but still unable to seperately alter x and y positions.

Thanks in advance.
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#2 Post by kivik »

Easiest thing is probably to create a separate screen with an additional parameter that tells the screen which layer to use, and then just call the screen.

You can store your xpos ypos in a dict or something and reference them in your screen then.

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#3 Post by Nicckonator »

LF> Example :oops: :lol:
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#4 Post by kivik »

I also just noticed you have box_wrap = True in the hbox, not sure if that's what caused the alignment problems? I didn't see where the cloud icon is set (I'm guessing it's in the style confirm_prompt, in which case you should probably change it to the vbox or something)

Untested:

Code: Select all

define confirm_prompts = {
	"quit": {"yes_x": 105, "yes_y": -38, "no_x": 105, "no_y": -38},
	"save": {"yes_x": 205, "yes_y": -38, "no_x": 205, "no_y": -38},
	"load": {"yes_x": 305, "yes_y": -38, "no_x": 305, "no_y": -38},
	}

screen my_confirm(confirm_type, yes_action, no_action):

    ## Ensure other screens do not get input while this screen is displayed.
    modal True
    zorder 200

    style_prefix "confirm"
    add "gui/overlay/confirm.png"

    frame:

        vbox:
            xalign .5
            yalign .5
            spacing 45

            label ("Dummy invisible text"):
                style "confirm_prompt"
                xalign 0.5
                text_color "#0000" # assuming you want it invisible for all

            hbox:
                box_wrap True
                vbox:

                    textbutton _("Yes") action yes_action
                    xpos confirm_prompts[confirm_type]["yes_x"]
                    ypos confirm_prompts[confirm_type]["yes_y"]

                vbox:

                    textbutton _("No") action no_action
                    xpos confirm_prompts[confirm_type]["no_x"]
                    ypos confirm_prompts[confirm_type]["no_y"]

label something:
    call screen my_confirm("quit", Quit(), Return())

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#5 Post by Nicckonator »

Code: Select all

style confirm_frame:
    background Frame([ "gui/confirm_frame.png", "gui/frame.png"], gui.confirm_frame_borders, tile=gui.frame_tile)
    padding gui.confirm_frame_borders.padding
    xpos 1080
    ypos 740
frame.png is the cloud icon, confirm_frame.png is just a fullscreen transparent, tried ur code 10-25-50-100%, didnt help it :( tried the box wrap false too, didnt change anything, also with your coding i suddenly had a black screen with a massive cloud :P
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#6 Post by kivik »

I just used my own confirm screen's code - you need to use yours to make it work, just look at the parts where I used the confirm_prompts variable and adopt that to your own code. Also I did disclaim untested because I was just focused on showing what I meant by making your own screen and using a dict for the x y pos :)

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#7 Post by Nicckonator »

Still not working sadly, my one little poofy cloud gets misformed into 2 evil clouds whenever i alter the code xD
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#8 Post by kivik »

Would help if you show us your latest code!

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#9 Post by Nicckonator »

Code: Select all

## Confirm screen ##############################################################
##
## The confirm screen is called when Ren'Py wants to ask the player a yes or no
## question.
##
## https://www.renpy.org/doc/html/screen_special.html#confirm

define confirm_prompts = {
"quit": {"yes_x": 105, "yes_y": -38, "no_x": 105, "no_y": -38},
"save": {"yes_x": 105, "yes_y": -38, "no_x": 105, "no_y": -38},
"load": {"yes_x": 105, "yes_y": -38, "no_x": 105, "no_y": -38},
}


screen confirm(message, yes_action, no_action):

    ## Ensure other screens do not get input while this screen is displayed.
    modal True

    zorder 200

    style_prefix "confirm"

    add "gui/overlay/confirm.png"

    frame:

        vbox:
            xalign .5
            yalign .5
            spacing 45

            label _(message):
                style "confirm_prompt"
                xalign 0.5
                text_color "#0000"



            hbox:
                box_wrap True

                vbox:

                    textbutton _("Yes") action yes_action
                    xpos 105
                    ypos -38

                vbox:

                    textbutton _("No") action no_action
                    xpos 105
                    ypos -38



    ## Right-click and escape answer "no".

    key "game_menu" action no_action


style confirm_frame is gui_frame
style confirm_prompt is gui_prompt
style confirm_prompt_text is gui_prompt_text
style confirm_button is gui_medium_button
style confirm_button_text is gui_medium_button_text

style confirm_frame:
    background Frame([ "gui/confirm_frame.png", "gui/frame.png"], gui.confirm_frame_borders, tile=gui.frame_tile)
    padding gui.confirm_frame_borders.padding
    xpos 1080
    ypos 740

style confirm_prompt_text:
    text_align 0.5
    layout "subtitle"

style confirm_button:
    properties gui.button_properties("confirm_button")

style confirm_button_text:
    properties gui.button_text_properties("confirm_button")
which results in:

quit being normal
quit.jpg
quit.jpg (23.59 KiB) Viewed 15146 times
save having normal text location but weird cloud
save.jpg
load having different text location and weird cloud
load.jpg
load.jpg (22.47 KiB) Viewed 15146 times
messing around a bit in the code with the placements and vbox/hboxes eventually results in something worse or no change at all.
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#10 Post by kivik »

You're still using the confirm screen - which is stretching to different sizes based on what's inside. In the code I posted I suggested using your own screen so that the screen size won't change based on the message.

There're a few things i recommend you do:

- restore the confirm screen code to original, replace the png file for the original confirm frame - unless you want all your confirm screens to have a cloud bubble.
- create your own confirm screen (read my code again, I declared a screen call "my_confirm". Use that for your custom confirm screens. You can call it whatever you want.
- read up on the screen language and styling if you haven't already - give your custom confirm screen a different prefix (instead of confirm, use something else that's unique)
- restyle your custom confirm screen
- give your custom confirm frame an xsize and ysize - this will keep the size of the frame static. You can remove the label.
- give the xpos ypos to your frame instead of the textbuttons. They will move relative to your frame.

When you want to customise your UI, you really oughta to learn the screen language so that you can understand what's actually happening step by step. Start by just making a frame, and use xpos ypos to move it around. Use xsize ysize to adjust the size, then start putting things inside until you've got it where and how you want it.

Good luck!

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#11 Post by Nicckonator »

I mean, i get that and ofcourse it makes sense, problem is the confirm screen (confirm.png) is just a full-screen 100% transparent overlay(the original confirm.png was transparent greyish) which is working as it should staying in the same place, and the frame screen (frame.png) is the actual cloud which is the one getting reshaped.
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#12 Post by kivik »

Yeah but your frame.png is declared as a Frame(): https://www.renpy.org/doc/html/displayables.html#Frame

That's not to be confused with a screen frame. A Frame() is a displayable that stretches and resizes automatically depending on what it's applied to: in this case your screen frame. You screen frame's size is determined by what's inside it. The reason it kept changing size is because the label's text _(message) varies depending on what the Confirm screen message is, so your cloud frame kept changing size.

To stop that - you set a size to the screen frame, so regardless of what messages are being sent to the screen, it won't change in size.

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#13 Post by Nicckonator »

Code: Select all

    frame:

        hbox:
            box_wrap False

            vbox:
                xsize 218
                ysize 145
                spacing 45


                hbox:
                    box_wrap False

                    vbox:

                        textbutton _("Yes") action yes_action
                        xpos 110
                        ypos 53

                    vbox:

                        textbutton _("No") action no_action
                        xpos 110
                        ypos 53
Managed to Macgyver fix it by altering my own code into this^ and then moving the frame.png cloud icon in photoshop to match the yes/no text location :P somehow it worked for all 3 screens.
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Yes/No prompts

#14 Post by kivik »

I'd strongly advise against that approach and actually learning the screen language to properly fix it. If you one day decide to change the layout, maybe add or remove a button, you'd have to go back to photoshop and redo your image if you keep to your solution. The whole point of a screen in renpy is that you can move it precisely where you need it - doing it that way defeats the point and can cause problems down the line.

Once again - commit to learning the renpy screen language a bit, try and understand what's going on, instead of ducktaping your code so that it works for one specific scenario only - it's a really bad way of developing!

Here's the link to the screen documentation: https://www.renpy.org/doc/html/screens.html

In fact, I just had a thought: if your game is played on a tablet or mobile device, your fix will probably fail immediately. You may not want that in this moment in time, but you're limiting yourself by this one decision already...

User avatar
Nicckonator
Regular
Posts: 35
Joined: Tue May 08, 2018 12:07 pm
Projects: Ochiba - Falling Leaves
Deviantart: Nicckonator
Contact:

Re: Yes/No prompts

#15 Post by Nicckonator »

I hear you, wont be releasing on anything other than PC, and no need to move the layout anymore now since it's finished, but ur advice is solid ofcourse, and thanks for the help. ;)
GD - Game Developer, and owner of NK Productions,
the company currently making Ochiba - Falling Leaves (Visual Novel).

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Andredron, Google [Bot], Semrush [Bot]