blockpy-edu / blockpy

Blockly that's more Python than JavaScript, powered with Skulpt
Apache License 2.0
391 stars 130 forks source link

Persisting small dictionaries might be broken #86

Open acbart opened 4 years ago

acbart commented 4 years ago

In BlockPy's compiler, it seems like it is possible for small dictionaries to be reset. In particular, this was triggered during the Text Adventure game project. Here's a note with a kludge to let students get by the issue, which might offer some suggestions as to what's wrong (you can use tag_phase_3.py as a test case, it's triggered by that).

This is definitely a bug in the underlying execution engine for BlockPy. I don't understand the bug, but I've got it pretty narrowed down. Without getting into details, you just need to make sure that your World has at least two fields. It doesn't even matter what the second field is, it can apparently be an int named "banana", and it will work just fine. So the solution for the students is "ignore that error and go onto the next phase" since they immediately define a second field in the next section. I'll be honest, I don't really know what the issue could be. This has to be something deep in the compiler that's going wrong - my suspicion is that BlockPy's compiler (which is named Skulpt) is doing some kind of incorrect optimization with "small" dictionaries, where it doesn't persist them. In effect, when the students' game is quit, it doesn't stick around. I have absolutely no idea why or how, and I don't have time to get into the compiler's inner workings right now, but it's definitely weird.