Problems updating certain projects to Renpy 8 from Renpy ~7.5

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
GoldenGob
Newbie
Posts: 8
Joined: Sat Dec 25, 2021 9:39 pm
itch: goldengob
Contact:

Problems updating certain projects to Renpy 8 from Renpy ~7.5

#1 Post by GoldenGob »

Hey all! I've run into problems with some parts of my code with my projects, particuarly my minigame code. It works with version 7 but when I run the project on renpy 8 it throws up errors. I've searched the renpy 8 incompatibility list and couldn't find the reason why the code isn't working, so I'm sure it's a problem between the python versions as I know renpy 8 is using python 3.

Some code that can't be ported:

Code: Select all

style Hacking_button:
    background None

style Hacking_button_text:
    font "GUI/Fonts/DIGIRU.ttf"
    size 30
    kerning 1.0
    #background "images/Minigames/HackMinigame/StaticMinigame2.png"
    color "#00FA9AE6"
    hover_color "#FF0000"
    outlines [ (1, "#000000", 0, 0) ]

style Timer_button_text:
    font "GUI/Fonts/DIGIRU.ttf"
    size 30
    kerning 1.0
    #background "images/Minigames/HackMinigame/StaticMinigame2.png"
    color "#00ADFF2F"
    hover_color "#00BFFFFF"
    outlines [ (1, "#000000", 0, 0) ]

transform roto_transform (roto_var):
    # ATL transform that will rotate our displayables to "roto_var" degrees
    rotate roto_var
    rotate_pad False

##### The game screen
screen numbers_scr():

    # It is better to operate this game with mouse only, so just disable cursor and enter keys
    key "K_LEFT" action Hide("nonexistent_screen")
    key "K_RIGHT" action Hide("nonexistent_screen")
    key "K_UP" action Hide("nonexistent_screen")
    key "K_DOWN" action Hide("nonexistent_screen")
    key "K_RETURN" action Hide("nonexistent_screen")
    key "K_KP_ENTER" action Hide("nonexistent_screen")

    ##### Timer
    #
    # It returns "smth" every second and "win" (if all buttons were clicked) or "lose" (if time was up)
    if Minigames_Active == 0:
        timer 1 action Return("win")

    timer 1 action [Return("smth"), If( game_timer>1, If(numbers_buttons[-1]["b_to_show"] == False, Return("win"), SetVariable("game_timer", game_timer-1) ), Return("lose") ) ] repeat True
    text "{color=#32CD32}[game_timer]" size 80 xpos 950 ypos 550 style "Timer_button_text"


    for each_b in sorted(numbers_buttons, reverse=True):
        if each_b["b_to_show"]:
            $ text_var = each_b["b_value"]
            $ i = each_b["b_number"] - 1
            button:

                # Will show image if "b_value" was set as file name or displayable.
                #background None
                #add each_b["b_value"]
                # Also it is neccessary to comment out the next  4 lines.

                #background "image.png"          # Sets button's appearance
                text '[text_var]{size=40}.{/size}' size 50 style "Hacking_button_text"
                #text '[text_var]{size=40}.{/size}' size 50 align (0.5, 0.55) style "Hacking_button_text"
                #xminimum 100 xmaximum 100
                #yminimum 100 ymaximum 100
                background Transform("images/Minigames/HackMinigame/StaticMinigame2.png",xalign=(0.5),yalign=(0.4))

                xysize 100, 100
                xpos each_b["b_x_pos"]
                ypos each_b["b_y_pos"]
                anchor (0.5, 0.5)
                action If (i == -1, SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                    If (numbers_buttons[i]["b_to_show"] == False,
                        SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                        SetVariable("game_timer", game_timer-1) )  )          # Wrong click reduces the time left by 1 second
                at roto_transform (renpy.random.randint (0, 10)*3)


    # It might be usefull to show the order of buttons to click if it's not obvious.
    #side "c b":
    frame:
        area (650, 850, 640, 70)         # The size of hint's area
        background None

        #viewport id "vp":
            #draggable True

        hbox:
            xalign 0.5

            # The same buttons declaration, but they will be scaled down
            for each_b in numbers_buttons:
                $ text_var = each_b["b_value"]
                button:

                    # Will show image if "b_value" was set as file name or displayable.
                    #background None
                    #add each_b["b_value"]
                    # Also it is neccessary to comment out the next  4 lines.

                    #background "image.png"          # Sets button's appearance
                    background Transform("images/Minigames/HackMinigame/StaticMinigame2.png",xalign=(0.5),yalign=(0.4))
                    text '[text_var]{size=18}.{/size}' size 50 style "Hacking_button_text"
                    xminimum 100 xmaximum 100
                    yminimum 100 ymaximum 100
                    action If (each_b["b_to_show"], Hide("nonexistent_screen"), None)
                    at Transform(zoom=0.9)           # Size

            #bar:

            #    value time_start
            #    range game_timer
            #    xalign 0.5
            #    xmaximum 300
                #    if time_start < (game_timer * 0.75):
                    #    left_bar "#f00"

        #bar value XScrollValue("vp")


#init:
    ##### Images
    #image img1 = "img1.png"
    #image img2 = "img2.png"

label Hack_Numbers_Game:

    call HideForScenes from _call_HideForScenes_12


    #####
    #
    # At first, let's set the values for buttons
    $ time_start = 0.7
    $ numbers_buttons = []
    $ buttons_values = [renpy.random.randint (1, 20)]

    # This might be numbers,
    

    # or letters,
   # $ buttons_values = [u"а", u"б", u"в", u"г", u"д", u"е", u"ё", u"ж", u"з", u"и", u"й", u"к", u"л", u"м", u"н", u"о", u"п", u"р", u"с", u"т", u"у", u"ф", u"х", u"ц", u"ч", u"ш", u"щ", u"ъ", u"ы", u"ь", u"э", u"ю", u"я" ]

    python:
        for i in range (1, renpy.random.randint (5, 7) ):
            buttons_values.append (str(i) )

    show HalfGreen
    with dissolve

    show PhoneNoIcons:
        yalign 0.5
        xalign 0.5

    show HackAnimImg:
        yalign 0.5
        xalign 0.5
        xzoom 0.6
        yzoom 0.7
    with easeinleft
    # or images,
    #$ buttons_values = ["img1", "img2", "my_img.png"]

    # This will make the description for all buttons (numbers, values and positions)
    python:
        for i in range (0, len(buttons_values)):
            numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (10, 70))*10, "b_y_pos":(renpy.random.randint (15, 50))*10, "b_to_show":True} )

    #"To win the game - click all the buttons one after another (start from \"1\")."

    # Before start the game, let's set the timer
    $ game_timer = 20

    # Shows the game screen
    show screen numbers_scr

    # The loop will exist untill game screen returns win or lose
    label loop:
        $ result = ui.interact()
        $ game_timer = game_timer

        if result == "smth":
            jump loop



    if result == "lose":
        hide screen numbers_scr
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        show screen QTE_press_button_Bad
        with hpunch
        hide PhoneNoIcons
        hide HackAnimImg

        with easeoutleft

        return

    if result == "win":
        hide screen numbers_scr


        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        hide PhoneNoIcons
        hide HackAnimImg

        with easeoutleft

        if Area == "Liz' Flat" and Liz_SearchFlatComputer_HACK == 1:
            show screen Liz_FlatSearch_HackedMessage1
            $ Liz_SearchFlatComputer_HACK = 2

        if Area == "My Bedroom" and MCRoom_Search_FirstCode_HACK == 2 and MCRoom_Search_UFAttackPlan1_HACK == 0:
            show screen Transmission1_UF_AttackPlan1
            $ MCRoom_Search_UFAttackPlan1_HACK = 2

        if Area == "My Bedroom" and MCRoom_Search_FirstCode_HACK == 0:
            show screen MCRoom_FirstCode_HackedMessage1
            $ MCRoom_Search_FirstCode_HACK = 2


        if Area == "Staff Room" and StaffRoom_Search_GoldGatePlan1_HACK == 0:
            show screen Transmission1_GoldGate_Plan1
            $ StaffRoom_Search_GoldGatePlan1_HACK = 2

        if Area == "College Classroom" and Classroom_Search_GoldGateArchitect1_HACK == 0:
            show screen Transmission1_GoldGateFuture_Plan2
            $ Classroom_Search_GoldGateArchitect1_HACK = 2

        if Area == "Gym" and MCRoom_Search_UFWarStart1_HACK == 0:
            show screen Transmission1_UF_War1
            $ MCRoom_Search_UFWarStart1_HACK = 2

        if Area == "Room" and Patreon_BrendaKateOF04_Hack == 0 and Kate_ExamBJEvent1 >= 1:
            $ Patreon_BrendaRoughZIM_07_Hack = 1
            jump SubstarComm1_0523_3someOF


        if Area == "Living Room" and Patreon_BrendaKate4Some0623_Hack == 0 and Holiday_Events == 3:
            $ Patreon_BrendaKate4Some0623_Hack = 1
            jump SubstarComm2_0623_4some_intro


        if Area == "Master Bedroom" and Patreon_BrendaRoughZIM_07_Hack == 0 and Brenda_Beach_Quest1 >= 1:
            $ Patreon_BrendaRoughZIM_07_Hack = 1
            jump Zim_Rough_Brenda_Commission_1
        if Area == "Kitchen" and Patreon_BrendaJaneCoffeehZIM_08_Hack == 0 and Brenda_Beach_Quest1 >= 1:
            $ Patreon_BrendaJaneCoffeehZIM_08_Hack = 1
            jump ZIMCoffee_2022_08

        if Area == "Upper Hall" and Patreon_BrendaJaneTrissDreamhZIM_10_Hack == 0 and Brenda_Beach_Quest1 >= 1:
            $ Patreon_BrendaJaneTrissDreamhZIM_10_Hack = 1
            jump BrendaJaneTrissDreamZIMM1022

        return


This script produces this error when trying to run in game:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 730, in script call
    $ renpy.pause(hard=True)
  File "game/Characters/Liz/CH_1/Liz_CH1_LizRoom.rpy", line 53, in script call
    call race_game from _call_race_game
  File "game/script.rpy", line 809, in script call
    call Call_Story_Variables_Jumper from _call_Call_Story_Variables_Jumper_4
  File "game/Interactables/MCRoom.rpy", line 81, in script call
    call Call_Story_Variables_Jumper from _call_Call_Story_Variables_Jumper_2
  File "game/script.rpy", line 730, in script call
    $ renpy.pause(hard=True)
  File "game/Minigames/F3Hacking.rpy", line 207, in script
    $ result = ui.interact()
  File "game/Minigames/F3Hacking.rpy", line 207, in <module>
    $ result = ui.interact()
  File "game/Minigames/F3Hacking.rpy", line 58, in execute
    screen numbers_scr():
  File "game/Minigames/F3Hacking.rpy", line 58, in execute
    screen numbers_scr():
  File "game/Minigames/F3Hacking.rpy", line 78, in execute
    for each_b in sorted(numbers_buttons, reverse=True):
  File "game/Minigames/F3Hacking.rpy", line 78, in <module>
    for each_b in sorted(numbers_buttons, reverse=True):
TypeError: '<' not supported between instances of 'RevertableDict' and 'RevertableDict'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 730, in script call
    $ renpy.pause(hard=True)
  File "game/Characters/Liz/CH_1/Liz_CH1_LizRoom.rpy", line 53, in script call
    call race_game from _call_race_game
  File "game/script.rpy", line 809, in script call
    call Call_Story_Variables_Jumper from _call_Call_Story_Variables_Jumper_4
  File "game/Interactables/MCRoom.rpy", line 81, in script call
    call Call_Story_Variables_Jumper from _call_Call_Story_Variables_Jumper_2
  File "game/script.rpy", line 730, in script call
    $ renpy.pause(hard=True)
  File "game/Minigames/F3Hacking.rpy", line 207, in script
    $ result = ui.interact()
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\ast.py", line 823, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\python.py", line 1178, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/Minigames/F3Hacking.rpy", line 207, in <module>
    $ result = ui.interact()
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\ui.py", line 301, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2165, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2687, in interact_core
    root_widget.visit_all(lambda d : d.per_interact())
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\displayable.py", line 431, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\displayable.py", line 431, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\displayable.py", line 431, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\screen.py", line 480, in visit_all
    callback(self)
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2687, in <lambda>
    root_widget.visit_all(lambda d : d.per_interact())
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\screen.py", line 491, in per_interact
    self.update()
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\display\screen.py", line 697, in update
    self.screen.function(**self.scope)
  File "game/Minigames/F3Hacking.rpy", line 58, in execute
    screen numbers_scr():
  File "game/Minigames/F3Hacking.rpy", line 58, in execute
    screen numbers_scr():
  File "game/Minigames/F3Hacking.rpy", line 78, in execute
    for each_b in sorted(numbers_buttons, reverse=True):
  File "game/Minigames/F3Hacking.rpy", line 78, in <module>
    for each_b in sorted(numbers_buttons, reverse=True):
  File "C:\Users\Robin\Documents\Renpy\renpy-7.3.5-sdk\renpy\revertable.py", line 277, in revertable_sorted
    return RevertableList(sorted(*args, **kwargs))
TypeError: '<' not supported between instances of 'RevertableDict' and 'RevertableDict'

Windows-10-10.0.19045 AMD64
Ren'Py 8.2.1.24030407
 0.2
Wed Apr 17 00:18:58 2024

I have issues with the other minigames as well. I may post them after this OP but don't want to overload the thread. Thanks for any help!

User avatar
GoldenGob
Newbie
Posts: 8
Joined: Sat Dec 25, 2021 9:39 pm
itch: goldengob
Contact:

Re: Problems updating certain projects to Renpy 8 from Renpy ~7.5

#2 Post by GoldenGob »

Another piece of code that's not porting to Renpy 8. For some reason the two added sprites (cars) are not showing up, they did with Renpy 7.

Code: Select all

screen game_scr():

    #### This part will let us interact with the screen.
    # Put it under the "timer_on" trigger to be able to show it
    # to the player without any interaction.
    if timer_on:
        #### Every 0.5 sec the game will change its state.
        timer 0.5 action Return("smth") repeat True

        key "x" action Return("a")
        key "X" action Return("a")
        key "c" action Return("d")
        key "C" action Return("d")
    #
    ####

    #### The background of the game screen.
    # If you have predefined image, like "image game bg = 'game_bg.png'",
    # you'll be able to add it simple like:
    # add "game bg"
    # Note: it is up to you to set the proper position for the bg
    # to let player know how far his car is from start and finish lines.
    #
    # But for now - some pseudographic bg
    add "images/Minigames/RaceGameBG2.webp"
    #text "   ================================== \n\n====================================" color "#c0c0c0" anchor (0.1, 0.5) pos (start_pos-125, 200)
    #text "#\n#" color "#c0c0c0" anchor (1.0, 0.5) pos (start_pos, 600)
    #text "#\n#" color "#c0c0c0" anchor (0.1, 0.5) pos (finish_pos, 600)
    #
    ####

    #### Some of the opponents.
    # Use this part if you've set the "opponents" list.
    # If not - then just comment or delete this part.
    #
    for i, each_opponent in enumerate(opponents):
        ####
        # If you've set the opponent's car appearence as an image
        # then show it as:
        add each_opponent["car"] anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 510-(len(opponents)-i)*5) at UpDownCarMinigame
        #
        # But for pseudographic it will be

        #text (each_opponent["car"]) color (each_opponent["car_color"]) anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 500-(len(opponents)-i)*5)
        #
        ####
    #
    ####

    #### Player's car.
    # If you have predefined image, like "image car = 'my_car.png'",
    # you'll be able to add it like:
    add "MCCar" anchor (1.0, 0.0) pos (car_pos, 270) at UpDownCarMinigame
    #
    # But for pseudographic car it will be
    #text "[car]" anchor (1.0, 0.0) pos (car_pos, 350)
    #
    ####

# The game starts here.
label race_game:


    #### Some variables that describes the game state.
    $ car = "images/Minigames/TomboyCar.webp"
    $ start_pos = 200
    $ finish_pos = 1600
    $ car_pos = (start_pos + finish_pos)/2
    #$ car_pos = 100
    $ last_pressed = ""
    $ timer_on = False

    #### The list of the opponents
    # (each one described by the dictionary).
    # If you have predefined image, like "image red car = 'red_car.png'",
    # you'll be able to set opponent's car appearence like:
    # "car":"red car"
    #
    $ opponents = [
        {"car_name":"Liz", "car":car, "car_color":"#c00", "opp_car_pos":(start_pos + finish_pos)/2, "opp_car_move":(-10, 0, 10, 20, 20, 20, 20, 40, 40)}]
    #
    ####

    scene black
    N "..."

    #### Let's show the game screen.
    #
    show screen game_scr

    N "Let's begin! (push 'x' and 'c' buttons)"

    #### And for now the player is able to interact with the game.
    #
    $ timer_on = True

    #### The game loop that has all its logic.
    #

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2410
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Problems updating certain projects to Renpy 8 from Renpy ~7.5

#3 Post by Ocelot »

1) you are trying to sort a list containing dictionaries. To do that Python applies operator < to dictionaries. Support for dict comparison was experimental and undocumented (read: should not be used) in Python2 and was completely removed in Python 3.

2) I am not sure there, but it could be constant variable optimisation. Was opponents defined before somewhere?
< < insert Rick Cook quote here > >

User avatar
GoldenGob
Newbie
Posts: 8
Joined: Sat Dec 25, 2021 9:39 pm
itch: goldengob
Contact:

Re: Problems updating certain projects to Renpy 8 from Renpy ~7.5

#4 Post by GoldenGob »

Ocelot wrote: Wed Apr 17, 2024 2:02 am 1) you are trying to sort a list containing dictionaries. To do that Python applies operator < to dictionaries. Support for dict comparison was experimental and undocumented (read: should not be used) in Python2 and was completely removed in Python 3.

2) I am not sure there, but it could be constant variable optimisation. Was opponents defined before somewhere?
What exactly should I change with that code to make it compatible? (Dictionaries)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2410
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Problems updating certain projects to Renpy 8 from Renpy ~7.5

#5 Post by Ocelot »

Just don't sort lists containing unsortable things.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users