UndertaleModTool icon indicating copy to clipboard operation
UndertaleModTool copied to clipboard

Compiler self call support

Open XdotCore opened this issue 1 year ago • 3 comments

Resolves #1133

Description

  1. Adds support for GMS2.3+ self calls in the compiler, cherrypicked from UndertaleModTool Community Edition.

  2. Fixed an issue where sub functions in an object should be stored in a self variable without the object function name suffix. Example: the utmt compiler would make gml_Script_act_gml_Object_menu_chapter_btn_Create_0 be stored in self.act_gml_Object_menu_chapter_btn_Create_0 when the original game code had self.act.

Caveats

None

Notes

I've tested this with Submachine Legacy (2023.8), and the one from #1133 (2022.5)

How to Reproduce:

  1. Create a function in a GlobalScript or Object code, then call that function from another function image

  2. In gamemaker (I've only tested this for 2023.8), make a function in an object, then call that function from another one in the same object image

XdotCore avatar Feb 17 '24 20:02 XdotCore

See also #564.

Jacky720 avatar Mar 05 '24 18:03 Jacky720

As a heads up, we'll probably be looking at merging this functionality in once the Underanalyzer decompiler is merged in. We do have a few things to make decisions about, though:

  • Do we consult the builtin function list to determine self calls, or do we make a setting on the decompiler to force self. notation?
  • Do we account for more complex chains of calls, like a.b().c().d(), or do we hold off until we (possibly) make a new compiler on the Underanalyzer side?

Curious for thoughts!

colinator27 avatar Jun 30 '24 14:06 colinator27

Just a note, UTMTCE's self calls have received further improvements since this PR, that are not in the PR (https://github.com/XDOneDude/UndertaleModToolCE/commit/19a4f44b8b4a81e6e22448b3f1c469e0b48b73a2 https://github.com/XDOneDude/UndertaleModToolCE/commit/aeb662421929adb0dd815e2f907b3090ff3cd9cf), and they now do support chains of calls and also local variables (although still using self, yeah I know it's messy):

var a = function() {
    return  {
        b: function() {
            return 123;
        }
    };
}
show_message(self.a().b()) // shows "123"

CST1229 avatar Jul 01 '24 13:07 CST1229