Page 1 of 1

ValueError with code I removed?

Posted: Sat Jul 30, 2022 6:32 pm
by voluorem
I'm getting a ValueError when I try and show my save screen, but the traceback shows a line of code I deleted. Here's the code I'm using:

Code: Select all

default playtime = 0

init python:

    def save_playtime(d):
        renpy.store.playtime += renpy.get_game_runtime()
        renpy.clear_game_runtime()
        d["playtime"] = renpy.store.playtime

    config.save_json_callbacks = [save_playtime]
    
screen file_slots(title):
    imagebutton:
        idle "gui/backgrounds/return_bg.png"
        hover "gui/backgrounds/return_bg.png"
        action Hide("save")

    add "gui/backgrounds/notesbg.png" at app_open xalign 0.5
    default page_name_value = FilePageNameInputValue(pattern=_("Page {}"), auto=_("Automatic saves"), quick=_("Quick saves"))
    frame at app_open:
        background None
        viewport:
            xpos 0
            ypos 50
            xfill False
            yfill False
            ymaximum 550
            mousewheel True

            grid gui.file_slot_cols gui.file_slot_rows at app_open:
                style_prefix "slot"

                xalign 0.5
                yalign 0.5

                spacing gui.slot_spacing

                for i in range(gui.file_slot_cols * gui.file_slot_rows):

                    $ slot = i + 1

                    button:
                        action [SetVariable("save_name", "%s"%calendar.string3()), FileAction(slot)]

                        has vbox

                        text FileSaveName(slot):
                            font "gui/fonts/Lato-Bold.ttf"
                            color "#9D755A"
                        $ playtime = FileJson(slot, "playtime", empty=0, missing=0) ## deleting this line got rid of the ValueError if that helps at all
                        $ minutes, seconds = divmod(int(playtime), 60)
                        $ hours, minutes = divmod(minutes, 60)
                        text "[hours]:[minutes]"
                        key "save_delete" action FileDelete(slot)
And this is the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 560, in script call
    call roomload
  File "game/technical.rpy", line 220, in script
    $ renpy.call_screen(place + "_" + current_room + "int")
  File "game/technical.rpy", line 220, in <module>
    $ renpy.call_screen(place + "_" + current_room + "int")
  File "game/screens.rpy", line 615, in execute
    screen save():
  File "game/screens.rpy", line 615, in execute
    screen save():
  File "game/screens.rpy", line 619, in execute
    use file_slots(_("Save"))
  File "game/screens.rpy", line 629, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 629, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 637, in execute
    frame at app_open:
  File "game/screens.rpy", line 639, in execute
    viewport:
  File "game/screens.rpy", line 647, in execute
    grid gui.file_slot_cols gui.file_slot_rows at app_open:
  File "game/screens.rpy", line 655, in execute
    for i in range(gui.file_slot_cols * gui.file_slot_rows):
  File "game/screens.rpy", line 659, in execute
    button:
  File "game/screens.rpy", line 662, in execute
    has vbox
  File "game/screens.rpy", line 668, in execute
    $ minutes, seconds = divmod(int(playtime), 60)
  File "game/screens.rpy", line 668, in <module>
    $ minutes, seconds = divmod(int(playtime), 60)
ValueError: invalid literal for int() with base 10: '[hours_display] : [minutes_display]'

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

Full traceback:
  File "game/script.rpy", line 560, in script call
    call roomload
  File "game/technical.rpy", line 220, in script
    $ renpy.call_screen(place + "_" + current_room + "int")
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\ast.py", line 1131, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\python.py", line 1049, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/technical.rpy", line 220, in <module>
    $ renpy.call_screen(place + "_" + current_room + "int")
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\exports.py", line 3161, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\ui.py", line 299, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 3377, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs) # type: ignore
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 3804, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 582, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 582, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 582, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\screen.py", line 451, in visit_all
    callback(self)
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\core.py", line 3804, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\screen.py", line 462, in per_interact
    self.update()
  File "C:\Users\thepr\Downloads\renpy-7.4.11-sdk\renpy\display\screen.py", line 653, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 615, in execute
    screen save():
  File "game/screens.rpy", line 615, in execute
    screen save():
  File "game/screens.rpy", line 619, in execute
    use file_slots(_("Save"))
  File "game/screens.rpy", line 629, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 629, in execute
    screen file_slots(title):
  File "game/screens.rpy", line 637, in execute
    frame at app_open:
  File "game/screens.rpy", line 639, in execute
    viewport:
  File "game/screens.rpy", line 647, in execute
    grid gui.file_slot_cols gui.file_slot_rows at app_open:
  File "game/screens.rpy", line 655, in execute
    for i in range(gui.file_slot_cols * gui.file_slot_rows):
  File "game/screens.rpy", line 659, in execute
    button:
  File "game/screens.rpy", line 662, in execute
    has vbox
  File "game/screens.rpy", line 668, in execute
    $ minutes, seconds = divmod(int(playtime), 60)
  File "game/screens.rpy", line 668, in <module>
    $ minutes, seconds = divmod(int(playtime), 60)
ValueError: invalid literal for int() with base 10: '[hours_display] : [minutes_display]'

Windows-10-10.0.22000 AMD64
Ren'Py 8.0.1.22070801
Sweet Release 1.0
Sat Jul 30 15:21:55 2022
I can't find [hours_display] : [minutes_display] anywhere (because I deleted it from my code). Is this some kind of cache issue? I cleared the cache and saves folders and deleted the persistent data, which still didn't fix it.

Re: ValueError with code I removed?

Posted: Sat Jul 30, 2022 9:01 pm
by Imperf3kt
The final 5 lines of what you posted (minus the very last line) are where this error is coming from.

Code: Select all

                        $ playtime = FileJson(slot, "playtime", empty=0, missing=0) ## deleting this line got rid of the ValueError if that helps at all
                        $ minutes, seconds = divmod(int(playtime), 60)
                        $ hours, minutes = divmod(minutes, 60)
                        text "[hours]:[minutes]"
The first line creates the data and adds it to the save data so it can be used.
The next two lines appear to set or get the time played for the save file and the last line displays that information to the player on the screen.

you have to delete all of these lines if you wish to remove this playtime counter from your save/load screens

Re: ValueError with code I removed?

Posted: Sun Jul 31, 2022 12:07 am
by voluorem
But it says the error is from [hours_display] : [minutes_display], not [hours]:[minutes]. I tried doing something else using hours_display and minutes_display (which didn't work, so I took it out), but it's still giving me errors like it's still there for some reason.

Re: ValueError with code I removed?

Posted: Sun Jul 31, 2022 8:04 am
by Alex
voluorem wrote:
Sun Jul 31, 2022 12:07 am
But it says the error is from [hours_display] : [minutes_display], not [hours]:[minutes]. I tried doing something else using hours_display and minutes_display (which didn't work, so I took it out), but it's still giving me errors like it's still there for some reason.
Did you restore game frome save? Don't use old saves when you changing your script - start a new game or use reload function.
Also such an error could occur when you deleted some rpy file, but not the corresponding rpyc file. Ren'Py uses rpyc files (it creates/updates them on project start), so try to delete all rpyc files (not rpy) and run your project.

Re: ValueError with code I removed?

Posted: Sun Jul 31, 2022 4:50 pm
by voluorem
I tried deleting all of the rpyc files and all of the saves and that still didn't fix it. I also tried clearing the cache and that also didn't do anything.

Re: ValueError with code I removed?

Posted: Sun Jul 31, 2022 5:04 pm
by Ocelot
Show your save screen. How you store data in file in particular. Error you got means that there is '[hours_display] : [minutes_display]' line stored within save file. Which is not a number. That is why integer conversion routine throws an error. Either you have old stray save file here, or you are saving data wrong.