How do locals not interfere with each other? #34
-
for example:
in this case, n becomes a local. I would expect the output of this program to be: 2112 Am I understanding this wrong? Did I write my program above incorrectly to expect 2112 as the output? Although I haven't figured out why... the program actually prints "20" and that's it. If I do T(3) it will print "30" and that's it. I am interested in understanding this better! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Ooops! I completely forgot about that! Thank you very much for highlighting this issue. Your expectations are correct, but the generated code isn't. Locals in functions are not actually "local": they're in the global namespace of Mindustry Logic. As you suspected, "but locals are not maintained". In your case, "n" should be pushed on the stack, and restored afterwards. I will create an issue for tracking purposes, and fix this in the coming days. Thank you very much for reporting this! |
Beta Was this translation helpful? Give feedback.
-
Note: in the provided code, This has been solved as part of the March 2023 update and the code nowadays indeed prints 2112, closing. |
Beta Was this translation helpful? Give feedback.
Ooops! I completely forgot about that! Thank you very much for highlighting this issue.
Your expectations are correct, but the generated code isn't. Locals in functions are not actually "local": they're in the global namespace of Mindustry Logic. As you suspected, "but locals are not maintained". In your case, "n" should be pushed on the stack, and restored afterwards.
I will create an issue for tracking purposes, and fix this in the coming days.
Thank you very much for reporting this!