screepers / typed-screeps

Strong TypeScript declarations for the game Screeps.
MIT License
191 stars 77 forks source link

Memory is constant and therefore throws an error when trying to assign to it #222

Open CEbbinghaus opened 1 year ago

CEbbinghaus commented 1 year ago

https://github.com/screepers/typed-screeps/blob/ae85cfda7f488e24f1005922bb6e5de2632b0fe7/src/memory.ts#L15

image

Pretty self explanatory. Directly encouraged by the docs this is needed for allowing for custom serialization

Jomik commented 1 year ago

No, it actually doesn't. It is trying to explain to you how access to Memory works :) Essentially, on first access in a tick, it will do a JSON parse of the raw memory and assign it to the variable. If you want to do the "memory hack", you could do something like https://github.com/Jomik/screeps-ai/blob/27a5edce0ac7920f5b4feb04c3dd6808527d3509/packages/bot/src/utils/memory-hack.ts#L9

I suppose the proper keyword would be let, but I think it is better to be very explicit if you mess with Memory, as it can really screw you over.