Page 1 of 1

Change to syntax to compile?

Posted: Mon Mar 25, 2024 10:20 am
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

Re: Change to syntax to compile?

Posted: Fri Mar 29, 2024 8:13 am
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):

Re: Change to syntax to compile?

Posted: Fri Mar 29, 2024 8:54 am
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).

Re: Change to syntax to compile?

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

Code: Select all

init python:
    from typing import Optional

Re: Change to syntax to compile?

Posted: Mon Apr 01, 2024 4:26 am
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