adding timers to CDD

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
Kakimito
Newbie
Posts: 11
Joined: Fri Dec 23, 2022 5:00 am
Contact:

adding timers to CDD

#1 Post by Kakimito »

I have a vending machine CDD (code at the end) and it works absolutely fine but now when I want to add some functionality Im stuck. so what I want: add a sound, start some timer, execute some action when this timer is finished. in my example I want to add a sound of coin/banknote inserted into vending machine and when this sound finishes it will add money value to already existing money. making everything but timer is okay but the only timer I found is like this time.sleep(0.5) and when it is started player can do nothing. literally nothing, even close the game

TLDR: I want to add a CDD timer at the end of which some predefined function will be executed

CDD code:

Code: Select all

    class VendingCDD(renpy.Displayable):

        def __init__(self):
            super(VendingCDD, self).__init__()
            self.Money = 0
            self.ButtonTexts = ["A","B","C","D","1","2","3","4","5","6","7","8","9","0"]
            self.Prices = {1:10,2:20,3:30,4:40,5:50,6:60,7:70,8:80,9:90,10:100,11:110,12:120}
            self.VKeypad = []
            self.FalseTexts = []
            self.ToHide = 0
            for x in self.ButtonTexts:
                self.VKeypad.append(Button(Text(text = x, text_align = 0.5, xalign = 0.5, yalign = 0.5), clicked = Function(self.PlusSymbol, x), xsize = 70, ysize = 70))
            self.VKeypad.insert(12,Button(Text(text = "<", text_align = 0.5, xalign = 0.5, yalign = 0.5), clicked = Function(self.MinusSymbol), xsize = 70, ysize = 70))
            self.VKeypad.append(Button(Text(text = "OK", text_align = 0.5, xalign = 0.5, yalign = 0.5), clicked = Function(self.Execute), xsize = 70, ysize = 70))
            self.VScreen = Text(text = "", yalign = 0.5, size = 80)
            self.CoinsCounter = Text(text = str(self.Money), size = 80)
            self.AddCoins = Button(Text(text = "+", size = 80), clicked = Function(self.CoinsChange, 1))
            self.RemoveCoins = Button(Text(text = "-", size = 80), clicked = Function(self.CoinsChange, -1))

        def PlusSymbol(self, numb):
            CurrentText = self.VScreen.get_all_text()
            if len(CurrentText)<6:
                if CurrentText != "X":
                    self.VScreen.set_text(CurrentText+numb)
                else:
                    self.VScreen.set_text(numb)
            renpy.play("button.mp3")

        def MinusSymbol(self):
            self.VScreen.set_text(self.VScreen.get_all_text()[:-1])

        def Execute(self):
            ### placeholder function below
            CurrentText = self.VScreen.get_all_text()
            if CurrentText in ["177013","117AD","2300BC"]:
                renpy.end_interaction(1) # palceholder
            elif CurrentText in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] and self.Money >= self.Prices[int(CurrentText)]:
                if (renpy.music.is_playing('vending')):
                    renpy.play("button_deny.mp3")
                else:
                    self.VScreen.set_text("")
                    renpy.play("vending_can_fall.mp3", channel="vending")
                    self.Money = self.Money - self.Prices[int(CurrentText)]
                    self.CoinsCounter.set_text(str(self.Money))
            else:
                self.VScreen.set_text("X")
                renpy.play("button_deny.mp3", channel="sound")

        def CoinsChange(self, x):
            ### placeholder function below
            self.Money = self.Money + (100 * x)
            self.CoinsCounter.set_text(str(self.Money))

        def event(self, *args):
            for x in self.VKeypad:
                x.event(*args)
            self.AddCoins.event(*args)
            self.RemoveCoins.event(*args)

        def render(self, w, h, st, at):
            r = renpy.Render(w, h)
            r.place(Image("panel.png"), 0, 0)
            r.place(self.CoinsCounter, 0, 250)
            r.place(self.AddCoins, 0, 500)
            r.place(self.RemoveCoins, 0, 750)
            for idx, x in enumerate(self.VKeypad):
                r.place(x, 1400+(105*(idx%4)), 310+(105*(math.floor(idx/4))))
            r.place(self.VScreen, 1400, -335)
            renpy.redraw(self, .0)
            return r

Post Reply

Who is online

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