Python (RenPy): текстовые кнопки, выполняющие функцию, которую они не вызывают явно при каждом нажатии - PullRequest
0 голосов
/ 16 января 2020

В игре, над которой я работаю, я использую массив для отслеживания текущей статистики компании игрока и следующую функцию для редактирования массива.

init python:

#The following store item objects, which include an array of their own stats
#Stores currently owned equipment
   Equipment = []
#Stores items available to buy
   Items = []
#Stores currently equipped equipment
   Equipped = []
#The company's current stats   
   SecArray = [0, 0, 0, 0, 0, 0]

#Called whenever moving something in or out of the currently equipped items.
#Pass the current item's stat array, the stat array, and a + or - symbol
   def arrayedit(array, SecArray, symbol):
        Notify("The stats have changed")
        if symbol == "+":
            SecArray[0] += array[0]
            SecArray[1] += array[1]
            SecArray[2] += array[2]
            SecArray[3] += array[3]
            SecArray[4] += array[4]
            SecArray[5] += array[5]
        if symbol == "-":
            SecArray[0] -= array[0]
            SecArray[1] -= array[1]
            SecArray[2] -= array[2]
            SecArray[3] -= array[3]
            SecArray[4] -= array[4]
            SecArray[5] -= array[5]
        return()

Если какие-либо элементы находятся в Массив «Equipment», однако, их статистика добавляется к текущей статистике каждый раз, когда нажимается текстовая кнопка (так, например, если у элемента есть 3 в статистике, текущая статистика игрока будет увеличиваться на 3 каждый раз любой Кнопка нажата, считая бесконечно вверх). Точно так же, если какие-либо предметы находятся в массиве «Оборудовано», их текущая статистика вычитается из текущей статистики игрока каждый раз, когда нажимается текстовая кнопка. Элементы в массиве «Элементы» не имеют никакого эффекта.

Следующий код предназначен для windows для покупки и оснащения / снаряжения оборудования.

screen shopping1():

    frame:
        xpos (config.screen_width*25/64) ypos (config.screen_height*11/64)
        ysize (config.screen_height*31/64)
        xsize (config.screen_width*36/64)

        has side "c r b"

        viewport:
            yadjustment tutorials_adjustment
            mousewheel True

            vbox:
              xpos (config.screen_width*2/5) ypos (config.screen_height*3/16)
              ysize (config.screen_height/2)
              xsize (config.screen_width/2)
              for i in Items:
                    if i.kind == "Item":
                      if i.cost <= Money:
                          textbutton "[i.title]   $[i.cost]":
                            action [AddToSet(Equipment, i), RemoveFromSet(Items, i), Hide("shopping1"), Return(i.cost)]
                            left_padding 20
                            xfill True
                            hovered Notify(i.hover)

                    else:
                        null height 10
                        text i.title alt ""
                        null height 5

              for i in Policies:
                    if i.kind == "Policy":
                      if i.cost <= Money:
                          textbutton "[i.title]   $[i.cost]":
                            action [AddToSet(OwnedPolicies, i), RemoveFromSet(Policies, i), Hide("shopping1"), Return(i.cost)]
                            left_padding 20
                            xfill True
                            hovered Notify(i.hover)                           

                    else:
                        null height 10
                        text i.title alt ""
                        null height 5

              for i in Trainings:
                    if i.kind == "Training":
                      if i.cost <= Money:
                          textbutton "[i.title]   $[i.cost]":
                            action [AddToSet(OwnedTrainings, i), RemoveFromSet(Trainings, i), Hide("shopping1"), Return(i.cost)]
                            left_padding 20
                            xfill True
                            hovered Notify(i.hover)

                    else:
                        null height 10
                        text i.title alt ""
                        null height 5

        bar adjustment tutorials_adjustment style "vscrollbar"

        textbutton _("Return"):
            xfill True
            action [Hide("shopping1")]
            top_margin 10

screen equipmentedit():

    frame:
        xpos (config.screen_width*5/128)  ypos (config.screen_height*2/64)
        ysize (config.screen_height*47/64)
        xsize (config.screen_width*19/64)

        has side "c r b"

        viewport:
            yadjustment tutorials_adjustment
            mousewheel True

            vbox:
              null height 10
              text "Unequipped Items" alt ""
              null height 5
              for i in Equipment:

                    if i.kind == "Item":

                        textbutton "[i.title]   $[i.cost]":
                            action [arrayedit(i.stats, SecArray, "+"), AddToSet(Equipped, i), RemoveFromSet(Equipment, i), Hide("equipmentedit"), Return(i.cost)]
                            left_padding 20
                            xfill True

                    else:

                        null height 10
                        text i.title alt ""
                        null height 5
              null height 10
              text "Equipped Items" alt ""
              null height 5
              for i in Equipped:

                    if i.kind == "Item":

                        textbutton "[i.title]   $[i.cost]":
                            action [arrayedit(i.stats, SecArray, "-"), AddToSet(Equipment, i), RemoveFromSet(Equipped, i), Hide("equipmentedit"), Return(i.cost)]
                            left_padding 20
                            xfill True

                    else:

                        null height 10
                        text i.title alt ""
                        null height 5




        bar adjustment tutorials_adjustment style "vscrollbar"

        textbutton _("Return"):
            xfill True
            action [Hide("equipmentedit")]
            top_margin 10

За пределами этого массивы и используемые функции не вызываются и не упоминаются в других местах программы. Я считаю, что функция "arrayedit" вызывается для элементов в оборудованных и оборудованных массивах каждый раз, когда нажимается кнопка, включая кнопки возврата, но я не знаю, почему. Любое понимание будет с благодарностью!

...