Code: Select all
init python:
from collections import defaultdict
default test_dict = defaultdict(int)
label start:
"Test A"
$ test_dict["key"] += 1
$ num = test_dict["key"]
"Current value: [num]"
"Test B"
This issue doesn't happen if I use a regular dictionary (replacing defaultdict(int) with {"key" : 0}); the current value stays at 1, as it should.
I'm not an expert with programming, but I assume it has to do with the fact that the value of the key isn't explicitly defined at the point we're trying to rollback to, it just uses the default value of 0. Is there any good way to work around this? If necessary I can switch to a regular dictionary and set all of the keys and values explicitly at the beginning, but a defaultdict would be a lot cleaner if possible.