UndertaleModTool icon indicating copy to clipboard operation
UndertaleModTool copied to clipboard

Copy Pasting Code Repeatedly Causes Local Var Count To Increment

Open SolventMercury opened this issue 4 years ago • 4 comments

I've discovered that alternately copy-pasting and deleting this snippet of code:

var hello = 13
draw_text(0, 0, string(hello))

As the sole code of a draw event, results in the line

.localvar 3 hello X

Incrementing the value of X by 1 each time you do so.

https://user-images.githubusercontent.com/87032239/142721285-76573170-1879-45ca-9ee6-04b69a6527d5.mp4

SolventMercury avatar Nov 20 '21 09:11 SolventMercury

Probably already known, but the cause for this is that every time var hello is written, a new code local hello gets created. When that code gets removed, UTMT doesn't check if hello is still in use / if it can be removed from the code locals list.

While it would be neat if UTMT could check that, it'd probably lead to weird behaviour. What if someone wanted to have a code local that isn't referenced by anything?

Miepee avatar Mar 20 '22 19:03 Miepee

I believe this should be resolved by https://github.com/UnderminersTeam/UndertaleModTool/pull/2056, if it wasn't already.

colinator27 avatar Mar 09 '25 03:03 colinator27

Apparently not. Is the new compiler intended to delete unused local variables, or merge with existing ones if possible when creating them?

Jacky720 avatar Mar 28 '25 22:03 Jacky720

Hmm... Just took a quick look, and it tries to reuse the locals when recompiling, but doesn't search the whole list to reuse a local. Maybe we should change that behavior, depending on official GM behavior.

colinator27 avatar Mar 28 '25 22:03 colinator27