Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: script variable references are sometimes dropped early #4158

Open
3 tasks done
cyn0x8 opened this issue Feb 16, 2025 · 2 comments
Open
3 tasks done

Bug Report: script variable references are sometimes dropped early #4158

cyn0x8 opened this issue Feb 16, 2025 · 2 comments
Labels
status: bug reproduced Involves a bug which can be reliably reproduced by reviewers. topic: mods Related to the creation or use of mods. type: minor bug Involves a minor bug or issue.

Comments

@cyn0x8
Copy link
Contributor

cyn0x8 commented Feb 16, 2025

Issue Checklist

  • I have read the Contributing Guide
  • I have checked the Issues/Discussions pages to see if my issue has already been reported
  • I have properly titled my issue

Platform

Compiled from GitHub Source Code

Browser

None

Version

0.5.3

Description (include any images, videos, errors, or crash logs)

like the title says, hscript seems to kinda "forget" variables references exist sometimes... and seemingly at random

its really annoying having to deal with this whenever it comes up and im completely stumped as to why this could be happening


so far ive encountered:

1.

after a script function ends, references to the parameters are just... dropped

the value stays if you assign it to something else, but referencing the parameter it originated from will always error if the function has already ended

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

public function example2(callback:()->Void, obj:Dynamic):Void {
    var callback_persist:()->Void = callback;
    var obj_persist:Dynamic = obj;
    
    new FlxTimer().start(1, function():Void {
        callback_persist(); // works perfectly fine??????
        trace(Std.string(obj_persist)); // also works fine
        
        callback(); // still errors like in example1
        trace(Std.string(obj)); // still errors like in example1
    });
}
2.

happens immediately after the variable is used in a trace inside a threaded Future made by a function thats called by a Timer. but only sometimes. what??????

Image


ill try to investigate more later and hopefully find more concrete reproducible examples

Steps to Reproduce

the only easily reproducible example i could get was the script function parameter one, but otherwise the behavior is really unpredictable... i couldnt even get the second example to reliably error or not error all the time

@cyn0x8 cyn0x8 added status: pending triage Awaiting review. type: minor bug Involves a minor bug or issue. labels Feb 16, 2025
@cyn0x8 cyn0x8 changed the title Bug Report: script function parameters dont persist Bug Report: references to script function parameters dont persist Feb 16, 2025
@AbnormalPoof AbnormalPoof added topic: mods Related to the creation or use of mods. status: bug reproduced Involves a bug which can be reliably reproduced by reviewers. and removed status: pending triage Awaiting review. labels Feb 16, 2025
@AbnormalPoof
Copy link
Collaborator

AbnormalPoof commented Feb 16, 2025

Encountered a similar (if not, the same) issue when working on Play Video Event:

// I was tired when making this.
switch (isCutscene) {
	case 2:
		shittyBool = true;
		iSwearToGodIWillLiterallyStrangleFNFTheFilePathIsLiterallyRightThereYouCanFindItStopLying = filePath;
		fuckingHell = mute;
		FlxTween.tween(PlayState.instance.camHUD, {alpha: 0}, duration, {
			ease: FlxEase.quadOut,
			onComplete: function(twn:FlxTween) {
				vidEvent.cameras = [PlayState.instance.camCutscene];
				PlayState.instance.camHUD.visible = false;
				vidEvent.play(iSwearToGodIWillLiterallyStrangleFNFTheFilePathIsLiterallyRightThereYouCanFindItStopLying);
				vidEvent.bitmap.mute = fuckingHell;
				recentTime = Conductor.instance.songPosition;
			}
		});
	case 3:
		vidEvent.cameras = [PlayState.instance.camCutscene];
		PlayState.instance.camHUD.visible = false;
		vidEvent.play(filePath);
		vidEvent.bitmap.mute = mute;
		recentTime = Conductor.instance.songPosition;
	default:
		vidEvent.cameras = [PlayState.instance.camHUD];
		vidEvent.play(filePath);
		vidEvent.bitmap.mute = mute;
		recentTime = Conductor.instance.songPosition;
}

@cyn0x8 cyn0x8 closed this as completed Feb 23, 2025
@AbnormalPoof AbnormalPoof added status: duplicate Issue or PR is redundant to another. and removed type: minor bug Involves a minor bug or issue. topic: mods Related to the creation or use of mods. status: bug reproduced Involves a bug which can be reliably reproduced by reviewers. labels Feb 23, 2025
Copy link

This issue is a duplicate. Please direct all discussion to the original issue.

@AbnormalPoof AbnormalPoof marked this as a duplicate of #4215 Feb 24, 2025
@AbnormalPoof AbnormalPoof reopened this Feb 24, 2025
@AbnormalPoof AbnormalPoof added type: minor bug Involves a minor bug or issue. topic: mods Related to the creation or use of mods. status: bug reproduced Involves a bug which can be reliably reproduced by reviewers. and removed status: duplicate Issue or PR is redundant to another. labels Feb 24, 2025
@cyn0x8 cyn0x8 changed the title Bug Report: references to script function parameters dont persist Bug Report: script variable references are sometimes dropped early Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: bug reproduced Involves a bug which can be reliably reproduced by reviewers. topic: mods Related to the creation or use of mods. type: minor bug Involves a minor bug or issue.
Projects
None yet
Development

No branches or pull requests

2 participants