Skip to content

Conversation

@NotHyper-474
Copy link

@NotHyper-474 NotHyper-474 commented Jan 21, 2026

Resolves #241

HScriptedClass.init is pretty odd because it's used throughout FNF as the equivalent of new for script classes, but it accepts the super class's constructor arguments as its own, and then initializes an instance of the script class using those arguments, however a script class is actually independent from the super class in this regard and can have any arguments it wants, which may not be the same the super class has. When scripts use it, it causes issues in some targets, where some of the arguments either get converted incorrectly, become null or, on HashLink, throws an error about the incompatible type.

One instance of that in FNF is phillyTrain.hxc, which instantiates an instance of BuildingEffectShader with ScriptedFlxRuntimeShader.init('BuildingEffectShader', 1.0), which calls an init of arguments (Null<String>, Null<String>, Null<String>), it works fine on C++ since there is no type-checking, but on HL it throws an error about being unable to cast a float to a string. This is not a mistake on the script's end, since it does accept a float as its argument.

So I've made it use haxe.Rest for the arguments, however since it doesn't work well with Reflect I had to add some backwards compatibility handling for scripts using it.

The registries and other parts of Haxe code that call init seem to work well with these changes somehow, but I recommend caution regarding any breaking changes this could introduce.

@NotHyper-474 NotHyper-474 changed the title [Possibly breaking] Change init to not use the super constructor arguments [Possible breaking change] Change init to not use the super constructor arguments Jan 21, 2026
Copy link
Collaborator

@EliteMasterEric EliteMasterEric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the change I linked, since you're making a potentially breaking change here and adding backwards compatibility for it anyway, it would be nice to implement #241 and rename init to scriptInit for consistency with the other generated methods.

@EliteMasterEric EliteMasterEric self-assigned this Jan 26, 2026
@NotHyper-474 NotHyper-474 changed the title [Possible breaking change] Change init to not use the super constructor arguments [Breaking Change] Rename init and make it not use the super constructor arguments Jan 26, 2026
The function:
* Has now been renamed to `scriptInit`.
* Will now take an arbitrary amount of arguments instead of copying the super class constructor.
@NotHyper-474
Copy link
Author

All done, though now that the function has received a new name it surely is a breaking change for existing Haxe code that used init now.

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

Successfully merging this pull request may close these issues.

2 participants