typed-screeps icon indicating copy to clipboard operation
typed-screeps copied to clipboard

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

Open CEbbinghaus opened this issue 2 years ago • 1 comments

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

CEbbinghaus avatar Jan 15 '23 07:01 CEbbinghaus

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.

Jomik avatar Oct 05 '23 13:10 Jomik