Page 1 of 1

[SOLVED]ordered dict???

Posted: Thu Nov 25, 2021 9:09 pm
by felsenstern
Hiya,

I lately noticed, that dict-variables inside of Ren'Py aren't ordered as they are in Python at least, they don't seem to work as they should. I've written a little game editor in Python (Python 3.10) that is using json files to exchange data between the editor and the Ren'Py game. To read the data in RenPy I am using json.loads which doesn't seem to have any problem. The problem only occurs when I read the dict with a loop something like:

Code: Select all

python:
	for i in dictTypeVar:
		renpy.say(None, "element: [i])
I get it in a random order.

I also tried to check if the dict type inside of Ren'Py would be the problem or the json.reads but I couldn't even create a dict inside of Ren'Py instead of a dict I get a <class 'renpy.python.RevertableDict'> which also isn't ordered, so I am a bit clueless here. Is the only way really that I number and sort the dict inside of Ren'Py, because in Python it doesn't seem to have any problem to be given out in the same order as it got created?

Re: ordered dict???

Posted: Thu Nov 25, 2021 9:51 pm
by Jackkel Dragon
Ren'Py currently runs using Python 2.7 internally, and the Python 3.x implementation has been ongoing for a while if I understand correctly. Until that support is part of the main Ren'Py release, it's best to treat Python statements in Ren'Py as a hybrid of the two and try to use Python that works in both. Since ordered dicts are part of Python 3.x, Ren'Py doesn't natively support them yet.

Re: ordered dict???

Posted: Fri Nov 26, 2021 1:41 am
by philat
OrderedDict is not in python 2.7 by default but you can import the module from collections, iirc.

Re: ordered dict???

Posted: Fri Nov 26, 2021 4:18 am
by felsenstern
Thanks a lot for clearing that up.