Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CEbbinghaus opened this issue Jan 15, 2023 · 1 comment

Comments

@CEbbinghaus
Copy link

declare const Memory: Memory;

image

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

@Jomik
Copy link
Contributor

Jomik commented Oct 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants