[Solved] 'restart' button progresses the script instead

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
daniople
Newbie
Posts: 7
Joined: Fri Oct 07, 2022 12:53 am
Completed: Mostly Harmless, Tastes like Coffee
Projects: Tomodachi Dan
Tumblr: daniople
itch: daniople
Contact:

[Solved] 'restart' button progresses the script instead

#1 Post by daniople »

Hello again! I'm still working on the game that I've mentioned in a previous post: viewtopic.php?f=8&t=65471. I've run into another issue, however.

Right now, I currently have a drink-crafting screen that shows 4 ingredients and a list of the 3 ingredients you've chosen. It also has a 'restart' imagebutton that does everything it's supposed to do upon being clicked (reset all ingredient values to 0, clear the screen of the listed ingredients) but it also closes the screen and progresses the script. :(

Image

I'd love to find a way to keep the drinktime screen active and on-screen no matter how many times the Reset button is clicked (or at least, until the Player presses the Brew button.) Thank you!

Here is all of the code for drink-making screen:

Code: Select all

screen drinktime:
    tag drinktime
    add "images/UI/brewbg.png" at my_center

    imagebutton:
        xpos 220
        ypos 250
        auto "images/UI/milk_%s.png"
        action SetVariable("milk", milk + 1), SetVariable("drink1_ingredients", drink1_ingredients + 1), If(drink1_ingredients == 0, Show("milk1")), If(drink1_ingredients == 1, Show("milk2")), If(drink1_ingredients == 2, Show("milk3"))

    imagebutton:
        xpos 220
        ypos 580
        auto "images/UI/honey_%s.png"
        action SetVariable("honey", honey + 1), SetVariable("drink1_ingredients", drink1_ingredients + 1), If(drink1_ingredients == 0, Show("honey1")), If(drink1_ingredients == 1, Show("honey2")), If(drink1_ingredients == 2, Show("honey3"))

    imagebutton:
        xpos 560
        ypos 250
        auto "images/UI/coffee_%s.png"
        action SetVariable("coffee", coffee + 1), SetVariable("drink1_ingredients", drink1_ingredients + 1), If(drink1_ingredients == 0, Show("coffee1")), If(drink1_ingredients == 1, Show("coffee2")), If(drink1_ingredients == 2, Show("coffee3")), SetVariable("drink1_coffee", True)

    imagebutton:
        xpos 560
        ypos 580
        auto "images/UI/tea_%s.png"
        action SetVariable("tea", tea + 1), SetVariable("drink1_ingredients", drink1_ingredients + 1), If(drink1_ingredients == 0, Show("tea1")), If(drink1_ingredients == 1, Show("tea2")), If(drink1_ingredients == 2, Show("tea3"))

    ## Below is the Restart Button!
    imagebutton:
        xpos 1025
        ypos 380
        idle "images/UI/restart.png"
        action SetVariable("milk", 0), SetVariable("tea", 0), SetVariable("coffee", 0), SetVariable("honey", 0), SetVariable("drink1_ingredients", 0), SetVariable("drink1_coffee", False), Call("HideIngredients")
        
    ## Below is the Brew Button!
    imagebutton:
        xpos 1000
        ypos 427
        auto "images/UI/brew_%s.png"
        action If(drink1_ingredients == 3, Jump("drinkconstruction")) and Call("HideIngredients")
Last edited by daniople on Thu Jan 19, 2023 2:56 am, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: 'restart' button progresses the script instead

#2 Post by _ticlock_ »

daniople wrote: Sun Nov 20, 2022 11:20 pm
Maybe that is not what you are looking but let me suggest a bit different approach:

Code: Select all

screen drinktime:
    tag drinktime
    add "images/UI/brewbg.png" at my_center
    
    default selected_ingredients = []
    
    vbox:
        #some position properties
        for ingredient in selected_ingredients:
            if ingredient == "milk":
                add milk_displayable
            elif ingredient == "honey":
                add honey_displayable
            elif ingredient == "coffee":
                add coffee_displayable
            elif ingredient == "tea":
                add tea_displayable
        
    imagebutton:
        xpos 220
        ypos 250
        auto "images/UI/milk_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["milk"]))

    imagebutton:
        xpos 220
        ypos 580
        auto "images/UI/honey_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["honey"]))
       

    imagebutton:
        xpos 560
        ypos 250
        auto "images/UI/coffee_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["coffee"]))

    imagebutton:
        xpos 560
        ypos 580
        auto "images/UI/tea_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["tea"]))

    ## Below is the Restart Button!
    imagebutton:
        xpos 1025
        ypos 380
        idle "images/UI/restart.png"
        action SetScreenVariable("selected_ingredients", [])
        
    ## Below is the Brew Button!
    imagebutton:
        xpos 1000
        ypos 427
        auto "images/UI/brew_%s.png"
        action If(len(selected_ingredients) == 3, Return(selected_ingredients))

Code: Select all

label some_label:
    call screen drinktime
Variable _return will have list of selected ingredients, for example:
["milk", "milk", "milk"]

User avatar
daniople
Newbie
Posts: 7
Joined: Fri Oct 07, 2022 12:53 am
Completed: Mostly Harmless, Tastes like Coffee
Projects: Tomodachi Dan
Tumblr: daniople
itch: daniople
Contact:

Re: 'restart' button progresses the script instead

#3 Post by daniople »

Thank you for the reply! This does seem to be a more efficient way of coding the drinktime screen. I'm unable to implement the code properly at the moment, but I'm sure I'd be able to make it work with more time and effort...!

However, I'm still at a loss on how to prevent my screen from progressing whenever I use the Restart button. :( I think I'll simply forgo the Restart button altogether and work around it instead.

Thank you for your time !!

User avatar
Tess
Regular
Posts: 59
Joined: Thu Aug 04, 2022 3:43 pm
Projects: The Songbird Guild
Organization: Yurisoft
Github: wainwt2
Discord: Tess#7782
Contact:

Re: 'restart' button progresses the script instead

#4 Post by Tess »

I think it's the "Call("HideIngredients")" action that's moving you away from your screen.

_ticlock_'s code gets around this by having a list that keeps track of the selected ingredients and only displaying what's in that list under ingredients. That lets you just clear the list and everything is taken care of.

If you're having trouble implementing it, let us know if there's a specific part that you're not familiar with and we can do our best to explain what it does. :)

User avatar
daniople
Newbie
Posts: 7
Joined: Fri Oct 07, 2022 12:53 am
Completed: Mostly Harmless, Tastes like Coffee
Projects: Tomodachi Dan
Tumblr: daniople
itch: daniople
Contact:

Re: 'restart' button progresses the script instead

#5 Post by daniople »

Hello, sorry for the late reply!

I have since released my visual novel on itch.io, but I wanted to get back to this since adding a 'restart' button would be a very big Quality of Life improvement! I think I now understand what _ticlock_'s code was going for, but I still continue to struggle with implementing certain parts of it. Thank you for your patience though!

What I'm struggling to implement is the following portion:

Code: Select all

    vbox:
        #some position properties
        for ingredient in selected_ingredients:
            if ingredient == "milk":
                add milk_displayable
            elif ingredient == "honey":
                add honey_displayable
            elif ingredient == "coffee":
                add coffee_displayable
            elif ingredient == "tea":
                add tea_displayable
This may be because I currently have the following code for when an ingredient gets selected (this decides on where each ingredient goes):

Code: Select all

screen milk1:
    add "images/UI/milk1.png" at ingredient1

screen milk2:
    add "images/UI/milk2.png" at ingredient2

screen milk3:
    add "images/UI/milk3.png" at ingredient3

screen honey1:
    add "images/UI/honey1.png" at ingredient1

screen honey2:
    add "images/UI/honey2.png" at ingredient2

screen honey3:
    add "images/UI/honey3.png" at ingredient3

screen tea1:
    add "images/UI/tea1.png" at ingredient1

screen tea2:
    add "images/UI/tea2.png" at ingredient2

screen tea3:
    add "images/UI/tea3.png" at ingredient3

screen coffee1:
    add "images/UI/coffee1.png" at ingredient1

screen coffee2:
    add "images/UI/coffee2.png" at ingredient2

screen coffee3:
    add "images/UI/coffee3.png" at ingredient3

transform ingredient1:
        xpos 1075 ypos 235

transform ingredient2:
        xpos 1075 ypos 300

transform ingredient3:
        xpos 1075 ypos 360
I have three different .pngs of each ingredient so that they wouldn't look so same-y if the Player selected all three of them at once, as well as three specific positions to decide on where each listed ingredient would go. With this in mind, would the code still work?

Here is what I have so far for the screen, which has worked wonderfully so far with everyone's help! I'm just struggling with screen placement. :')

Code: Select all

screen drinktime:
    tag drinktime
    add "images/UI/brewbg.png" at my_center

    default selected_ingredients = []

    vbox:

        for ingredient in selected_ingredients:
            if ingredient == "milk":
                add "images/UI/milk1.png"
            elif ingredient == "honey":
                add "images/UI/honey1.png"
            elif ingredient == "coffee":
                add "images/UI/coffee1.png"
            elif ingredient == "tea":
                add "images/UI/tea1.png"

    imagebutton:
        xpos 220
        ypos 250
        auto "images/UI/milk_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["milk"]))

    imagebutton:
        xpos 220
        ypos 580
        auto "images/UI/honey_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["honey"]))

    imagebutton:
        xpos 560
        ypos 250
        auto "images/UI/coffee_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["coffee"]))

    imagebutton:
        xpos 560
        ypos 580
        auto "images/UI/tea_%s.png"
        action If(len(selected_ingredients) < 3, SetScreenVariable("selected_ingredients", selected_ingredients + ["tea"]))

    ## Below is the Restart Button!
    imagebutton:
        xpos 1025
        ypos 380
        idle "images/UI/restart.png"
        action SetScreenVariable("selected_ingredients", [])

    ## Below is the Brew Button!
    imagebutton:
        xpos 1000
        ypos 427
        auto "images/UI/brew_%s.png"
        action If(len(selected_ingredients) == 3, Return(selected_ingredients))

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: 'restart' button progresses the script instead

#6 Post by _ticlock_ »

daniople wrote: Thu Jan 19, 2023 2:07 am I have three different .pngs of each ingredient so that they wouldn't look so same-y if the Player selected all three of them at once, as well as three specific positions to decide on where each listed ingredient would go. With this in mind, would the code still work?

Here is what I have so far for the screen, which has worked wonderfully so far with everyone's help! I'm just struggling with screen placement. :')
Let me suggest the following:
You don’t really need screens for each ingredient or transforms. We can place the desired images into right places using the position of the ingredient in the list selected_ingredients.

Code: Select all

screen drinktime:
    tag drinktime
    add "images/UI/brewbg.png" at my_center

    default selected_ingredients = []
    default i_ypos = [235, 300, 360]

    vbox:

        for i, ingredient in enumerate(selected_ingredients):
            if ingredient == "milk":
                add "images/UI/milk{}.png".format(i+1):
                    xpos 1075 ypos i_ypos[i]
            elif ingredient == "honey":
                add "images/UI/honey{}.png".format(i+1):
                    xpos 1075 ypos i_ypos[i]
            elif ingredient == "coffee":
                add "images/UI/coffee{}.png".format(i+1):
                    xpos 1075 ypos i_ypos[i]
            elif ingredient == "tea":
                add "images/UI/tea{}.png".format(i+1):
                    xpos 1075 ypos i_ypos[i]

 

User avatar
daniople
Newbie
Posts: 7
Joined: Fri Oct 07, 2022 12:53 am
Completed: Mostly Harmless, Tastes like Coffee
Projects: Tomodachi Dan
Tumblr: daniople
itch: daniople
Contact:

Re: 'restart' button progresses the script instead

#7 Post by daniople »

This works perfectly, thank you so much! ^^

Post Reply

Who is online

Users browsing this forum: Andredron, Google [Bot]