Button actions performed on screen call without clicking them?

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
chadochocinco
Newbie
Posts: 5
Joined: Mon Nov 12, 2018 5:23 pm
Contact:

Button actions performed on screen call without clicking them?

#1 Post by chadochocinco »

Hey all,

I have a problem where I'm calling a screen to display variables and buttons, and long story short: I click a button to move to a new location, and my time advances 120 minutes (the combined total of all my time updates for my buttons). It would appear that, when I jump to new location and make my screen calls, it displays my time properly, but on the call, the action of my text buttons all gets performed.

How do I correct this/prevent this from happening? Why would the actions from my buttons be getting done without clicking them?

I expect to click the text button, have timeofday increase by that much time via the clock(amount) function. I'd also love the screens to refresh on clicking that, but that'll be my follow-up (couldn't figure out how to get renpy.restart_interaction() to work).

Code: Select all

    
    	init 2 python:

###########################
# Routines                #
###########################
    	def clock(amount):
        global timeofday
        global day
        global daydisplay
        global dayname
        timeofday = timeofday + int(amount)
        if timeofday > 1440:
            timeofday = timeofday - 1440
            day = day + 1
            daydisplay = dayname [((day-1)%7)]
            return
        elif timeofday < 0:
            timeofday = 0
            return
        else:
            timeofday = timeofday
            return

screen headsupdisplay:
    zorder -1
    $clockhour = int(timeofday/60)
    $clockmin = timeofday - (clockhour * 60)
    $money_k = int(money)

    add "genuitop"
    vbox xpos 1700 ypos 10:
        hbox xpos 40 ypos 10:
            if clockhour < 10:
                text "{=clock_text}0[clockhour]"
            else:
                text "{=clock_text}[clockhour]"
            if clockmin < 10:
                text "{=clock_text}:0[clockmin]"
            else:
                text "{=clock_text}:[clockmin]"
        hbox xpos 40 spacing 5:
            vbox:
                textbutton "{=clock_button_text}5" action clock(5)
            vbox:
                textbutton "{=clock_button_text}10" action clock(10)
            vbox:
                textbutton "{=clock_button_text}15" action clock(15)
            vbox:
                textbutton "{=clock_button_text}30" action clock(30)
            vbox:
                textbutton "{=clock_button_text}60" action clock(60)

    vbox xalign .5 ypos 10:
        text "{=stats_text}[daydisplay], Day [day]"

    vbox xalign .5 ypos 50:
        text "{=stats_text}[location]"


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: Button actions performed on screen call without clicking them?

#3 Post by trooper6 »

That post about currying is a bit out of date. The OP should just use the Function action, which does take variables.
https://www.renpy.org/doc/html/screen_a ... l#Function

On the other hand...there is a lot I'd do differently with that code in general.
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

chadochocinco
Newbie
Posts: 5
Joined: Mon Nov 12, 2018 5:23 pm
Contact:

Re: Button actions performed on screen call without clicking them?

#4 Post by chadochocinco »

trooper6 wrote: Mon Nov 12, 2018 7:20 pm That post about currying is a bit out of date. The OP should just use the Function action, which does take variables.
https://www.renpy.org/doc/html/screen_a ... l#Function

On the other hand...there is a lot I'd do differently with that code in general.
I'll gladly accept any advice - trust me, I'm stumbling through all of this and welcome guidance.

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: Button actions performed on screen call without clicking them?

#5 Post by trooper6 »

What is {=clock_button_text} and {=stats_text}? Also you have money_k as a variable, but I don't see where it is used in that 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

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Button actions performed on screen call without clicking them?

#6 Post by philat »

It's somewhat out of date but the principle concept (that you should not use functions in screens unless curried or wrapped in an Action of some sort) still stands, which was the main point. Also, currying still works perfectly fine.

chadochocinco
Newbie
Posts: 5
Joined: Mon Nov 12, 2018 5:23 pm
Contact:

Re: Button actions performed on screen call without clicking them?

#7 Post by chadochocinco »

trooper6 wrote: Mon Nov 12, 2018 8:38 pm What is {=clock_button_text} and {=stats_text}? Also you have money_k as a variable, but I don't see where it is used in that screen.
Styles
style clock_text:
color "#F0F0F0"
font "gui/font/consolas.ttf"
size 40

style clock_button_text:
color "#FF9900"
font "gui/font/consolas.ttf"
size 20

money_k was a leftover for something I was going to have displayed in the hud, but am redesigning as well.

chadochocinco
Newbie
Posts: 5
Joined: Mon Nov 12, 2018 5:23 pm
Contact:

Re: Button actions performed on screen call without clicking them?

#8 Post by chadochocinco »

And thank you guys for your answers so far. Wasn't familiar with currying, but it makes sense how I should approach this now

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: Button actions performed on screen call without clicking them?

#9 Post by trooper6 »

Here is the code as I'd do it. This is tested and it works...you'd probably just want to change some of the styling.

Code: Select all

init python:
    class Calendar(object):
        def __init__(self):
            self.timeofday = 0
            self.day = 1
            self.daydisplay = "Sunday"
            self.dayname = ["Sunday", "Monday", "Tuesday", "Wednesaday", "Thursday", "Friday", "Saturday"]
        def advance(self, amount):
            self.timeofday += amount
            if self.timeofday > 1440:
                self.timeofday -= 1440
                self.day += 1
                self.daydisplay = self.dayname[((self.day-1)%7)]
            elif self.timeofday < 0:
                self.timeofday = 0
            return
        def timestring(self):
            ch = self.timeofday/60
            cm = self.timeofday - (ch*60)
            return "{:02d}:{:02d}".format(ch, cm)

default cal = Calendar()

screen headsupdisplay():
    zorder -1
    frame:
        vbox:
            text "{}".format(cal.timestring())
            hbox:
                textbutton "5" action Function(cal.advance, 5)
                textbutton "10" action Function(cal.advance, 10)
                textbutton "15" action Function(cal.advance, 15)
                textbutton "30" action Function(cal.advance, 30)
                textbutton "60" action Function(cal.advance, 60)

            text "[cal.daydisplay], Day [cal.day]"
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], snotwurm