Serialization works, but unerialized crashes

I am trying to set up a save function in my HaxeFlixel game.

Some background: the subject in question is an instance Playerthat expands FlxSprite. Saving data is stored in an instance of a custom class that I made for it. This instance is stored in StringMap(keys are save names), which is saved by serializing it into a variable in FlxSave.

Creating and saving saved data works great. However, reading the save data back causes the game to crash with the message "Invalid field: pixels." pixelsis a field from FlxSprite, but this is not the first such field in a serialized string, so this is probably not the case.

If useful, declaring this field y6:pixelsnis:

  • y run the field called ...
  • 6: string length 6 ...
  • pixels (line)
  • n null
+5
source share
1 answer

From this line of code, you can see that pixelsthey are not really * variable at runtime. Thus, the non-serializer will crash when trying to assign a value pixels. But we need to investigate more why the serializer first serialized the fields pixelsbecause it should not exist at run time.

Note *: Accessors pixelsare (get, set)what makes a pixelsnon-real property at runtime. Find out more here .

, FlxSprite ( ) . , (, x/y position hp ..) .

+3

All Articles