attrgetter inventory problem in Renpy 8?

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
liambeale
Newbie
Posts: 12
Joined: Wed Aug 17, 2022 12:56 am
itch: noirinhongkong
Contact:

attrgetter inventory problem in Renpy 8?

#1 Post by liambeale »

Hey everyone,

I have an inventory system that had been working well in Renpy 7.5, which would store text messages to display them in a scrollable chronological fashion like in Whatsapp, etc. It worked perfectly well in 7.5 but upon upgrading to Renpy 8, an error occurs every time I try to access the phone.

The culprit seems to be the opening line of the screen :

screen wchatnull:
zorder 90
modal True
$ sorted_witems = sorted(inventorywchat.items, key=attrgetter('order'), reverse=False)
$ sorted_itemswchat = sorted_witems

I've played around with removing the line entirely and the game flows again. Can anyone shed some light on what exactly Renpy 8 doesn't like about it?

Thanks,
Liam
-----------------------------

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 16224, in script
    show screen wchatnull
  File "renpy/common/000statements.rpy", line 588, in execute_show_screen
    renpy.show_screen(name, *args, **kwargs)
  File "game/screens.rpy", line 6722, in execute
    screen wchatnull:
  File "game/screens.rpy", line 6722, in execute
    screen wchatnull:
  File "game/screens.rpy", line 6725, in execute
    $ sorted_witems = sorted(inventorywchat.items, key=attrgetter('order'), reverse=False)
  File "game/screens.rpy", line 6725, in <module>
    $ sorted_witems = sorted(inventorywchat.items, key=attrgetter('order'), reverse=False)
TypeError: '<' not supported between instances of 'RevertableList' and 'int'

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

Full traceback:
  File "game/script.rpy", line 16224, in script
    show screen wchatnull
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\ast.py", line 2232, in execute
    self.call("execute")
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\ast.py", line 2220, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\statements.py", line 281, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 588, in execute_show_screen
    renpy.show_screen(name, *args, **kwargs)
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\display\screen.py", line 1218, in show_screen
    sls.add(_layer, d, _tag, zorder=_zorder, transient=_transient, keep_st=True, name=name)
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\display\core.py", line 1132, in add
    if not self.hide_or_replace(layer, remove_index, "replaced"):
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\display\core.py", line 1191, in hide_or_replace
    if not oldsle.displayable._handles_event(prefix):
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\display\screen.py", line 500, in _handles_event
    self.update()
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\display\screen.py", line 653, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 6722, in execute
    screen wchatnull:
  File "game/screens.rpy", line 6722, in execute
    screen wchatnull:
  File "game/screens.rpy", line 6725, in execute
    $ sorted_witems = sorted(inventorywchat.items, key=attrgetter('order'), reverse=False)
  File "game/screens.rpy", line 6725, in <module>
    $ sorted_witems = sorted(inventorywchat.items, key=attrgetter('order'), reverse=False)
  File "C:\Users\ljbea\Desktop\renpy-8.0.3-sdk\renpy\revertable.py", line 281, in revertable_sorted
    return RevertableList(sorted(*args, **kwargs))
TypeError: '<' not supported between instances of 'RevertableList' and 'int'

Windows-10-10.0.22000 AMD64
Ren'Py 8.0.3.22090809
NOIRINHK 1.0
Fri Nov 25 10:32:39 2022

User avatar
liambeale
Newbie
Posts: 12
Joined: Wed Aug 17, 2022 12:56 am
itch: noirinhongkong
Contact:

Re: attrgetter inventory problem in Renpy 8?

#2 Post by liambeale »

Ok - I think I got to the bottom of the issue.

I noticed that other screens actually use an identical attrgetter system but don't result in a crash, so I had to consider that the actual items within the inventory system were the problem.

The chat messages systems previously had a variable in order to weight the order they would appear. They would look something like:

bethere = Item("I'll be there!","2", [wchat])

and then with each message, the [wchat] number would increase, so they would always be in chronological order.

What I've found is that such a system isn't accepted in Renpy 8 and that writing the numbers manually gets around the problem. It's slightly less flexible (as I'll have to predict in advance the order players will send as receive messages) but it does, crucially, allow the game to function.

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

Re: attrgetter inventory problem in Renpy 8?

#3 Post by Ocelot »

Why do you use a list of a single element instead of directly using variable?
< < insert Rick Cook quote here > >

User avatar
liambeale
Newbie
Posts: 12
Joined: Wed Aug 17, 2022 12:56 am
itch: noirinhongkong
Contact:

Re: attrgetter inventory problem in Renpy 8?

#4 Post by liambeale »

That's a very good point!

The honest answer is - I dunno. I had it like that and it worked (in 7.5) so I didn't consider changing it.

Let me have a play with using a direct variable and I'll get back to you about whether Renpy 8 accepts it.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]