Change to syntax to compile?

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Change to syntax to compile?

#1 Post by RewindTheGame »

I know I've seen this in an update log somewhere, but I can't for the life of me find it now. Moving up from RenPy 8.1.3 to the latest version, I get this error in the inventory code. I think it's something to do with the way the -> format has changed and simply requires a syntax change to some lines of code, but I can't remember where I saw the fix and can't find it now. Can anyone help?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/inventory.rpy", line 676, in script
    init python:
  File "game/inventory.rpy", line 676, in script
    init python:
  File "game/inventory.rpy", line 684, in <module>
    def findLast(l: list, val) -> Optional[int]:
NameError: name 'Optional' is not defined

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#2 Post by jeffster »

Type hints give that error in the latest builds. I think it's just a temporary development thing. Just use some stable release instead of "nightly" or whatever you are using.

Otherwise, just delete those type hints - here parts between ) and :.

Instead of

Code: Select all

    def findLast(l: list, val) -> Optional[int]:
this should work:

Code: Select all

    def findLast(l: list, val):
or this:

Code: Select all

    def findLast(l, val):
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#3 Post by jeffster »

RewindTheGame wrote: Mon Mar 25, 2024 10:20 am I know I've seen this in an update log somewhere, but I can't for the life of me find it now. Moving up from RenPy 8.1.3 to the latest version, I get this error in the inventory code.
PS. Oops, no, I believe that's a bug in Ren'Py.
viewtopic.php?t=68117

For now the way to get rid of those errors is either use Ren'Py 8.1, or delete those type hints from the script (there are just a few of them).
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

User avatar
PyTom
Ren'Py Creator
Posts: 16098
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Change to syntax to compile?

#4 Post by PyTom »

You probably need:

Code: Select all

init python:
    from typing import Optional
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#5 Post by jeffster »

PyTom wrote: Mon Apr 01, 2024 2:08 am You probably need:

Code: Select all

init python:
    from typing import Optional
I wonder why Ren'Py 8.1 didn't need that import line. Now it needs

Code: Select all

init python:
    from typing import Optional, Union
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Change to syntax to compile?

#6 Post by RewindTheGame »

Thanks everyone, I've only just seen this. Glad it wasn't just me. I'll try this out tonight, because I really would like to be using the latest version of RenPy - mainly because I need the "retain" feature of speech bubbles which my current version doesn't support...

Post Reply

Who is online

Users browsing this forum: No registered users