Skip to content

Fix local functions not affecting variables, again...#342

Merged
AbnormalPoof merged 1 commit intoFunkinCrew:experimentalfrom
NotHyper-474:sorry-kolo
Feb 11, 2026
Merged

Fix local functions not affecting variables, again...#342
AbnormalPoof merged 1 commit intoFunkinCrew:experimentalfrom
NotHyper-474:sorry-kolo

Conversation

@NotHyper-474
Copy link

@NotHyper-474 NotHyper-474 commented Feb 10, 2026

This is more of a provisional fix, since the current system is very susceptible to edge cases. It should probably be entirely reworked in the future. Also, sorry but I decided it was better off killing clone for this.

Obligatory test script to ensure nothing broke.
import funkin.modding.module.Module;
import flixel.util.FlxTimer;
import flixel.FlxG;

class Script1 extends Module
{
  function new()
  {
    super("script1", -99999);
  }

  var test:String = null;

  public override function onUpdate(event:ScriptEvent):Void
  {
    super.onUpdate(event);

    if (FlxG.keys.justPressed.ONE)
    {
      FlxTimer.wait(1., () -> {
        testFunc();
      });

      FlxTimer.wait(1.5, () -> {
        trace('Test in route 1: $test');
        test = null;
      });

      FlxTimer.wait(2., () -> {
        testFunc(false);
      });

      FlxTimer.wait(2.5, () -> {
        trace('Test in route 2: $test');
        test = null;
      });

      FlxTimer.wait(3, () -> {
        trace('Test at the end: $test');
        example1(() -> trace('Callback called!'), 67);
      });

    }
  }


  function testFunc(route1:Bool = true)
  {
    if (route1) this.test = toString() + ' 1';
    else test = toString() + ' 2';

    trace('${route1 ? '1' : '2'} - test set to $test');
  }

  public function example1(callback:() -> Void, obj:Dynamic):Void
  {
    FlxTimer.wait(1, function():Void {
      callback(); // errors saying it cant find "callback"
      trace(Std.string(obj)); // will also error saying it cant find "obj"
    });
  }
}

Sorry `clone`. You were good son, real good, maybe even the best.
@AbnormalPoof AbnormalPoof self-requested a review February 11, 2026 02:05
@AbnormalPoof AbnormalPoof merged commit 6363153 into FunkinCrew:experimental Feb 11, 2026
@NotHyper-474 NotHyper-474 deleted the sorry-kolo branch February 11, 2026 02:30
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