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

Enhancement: Null coalescing support for HScript #3767

Open
2 tasks done
AbnormalPoof opened this issue Oct 25, 2024 · 2 comments
Open
2 tasks done

Enhancement: Null coalescing support for HScript #3767

AbnormalPoof opened this issue Oct 25, 2024 · 2 comments
Labels
status: pending triage The bug or PR has not been reviewed yet. type: enhancement Provides an enhancement or new feature.

Comments

@AbnormalPoof
Copy link
Contributor

AbnormalPoof commented Oct 25, 2024

Issue Checklist

  • I have properly named my enhancement
  • I have checked the Issues/Discussions pages to see if my enhancement has already been suggested

What is your suggestion, and why should it be implemented?

Null coalescing is a Haxe language feature that allows you to specify a fallback value if an expression is null. This would greatly improve readability of scripts that access a lot of null-able values.

Example:

// BEFORE
if (characterData != null && type == 'bf') {
	PauseSubState.musicSuffix = (characterData.pauseMusicSuffix != null
		&& characterData.pauseMusicSuffix != '') ? characterData.pauseMusicSuffix : PauseSubState.musicSuffix;
	GameOverSubState.musicSuffix = (characterData.gameOverMusicSuffix != null
		&& characterData.gameOverMusicSuffix != '') ? characterData.gameOverMusicSuffix : GameOverSubState.musicSuffix;
	GameOverSubState.blueBallSuffix = (characterData.blueBallSuffix != null
		&& characterData.blueBallSuffix != '') ? characterData.blueBallSuffix : GameOverSubState.blueBallSuffix;
}

// AFTER
if (type == 'bf') {
	PauseSubState.musicSuffix = characterData?.pauseMusicSuffix ?? PauseSubState.musicSuffix;
	GameOverSubState.musicSuffix = characterData?.gameOverMusicSuffix ?? GameOverSubState.musicSuffix;
	GameOverSubState.blueBallSuffix = characterData?.blueBallSuffix ?? GameOverSubState.blueBallSuffix;
}
@AbnormalPoof AbnormalPoof added status: pending triage The bug or PR has not been reviewed yet. type: enhancement Provides an enhancement or new feature. labels Oct 25, 2024
@AbnormalPoof
Copy link
Contributor Author

FYI there's a PR for this (HaxeFoundation/hscript#131) but it's been open for 3-4 months.

@biomseed
Copy link

FYI there's a PR for this (HaxeFoundation/hscript#131) but it's been open for 3-4 months.

Funkin Crew has their own fork so they can just merge that in no problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending triage The bug or PR has not been reviewed yet. type: enhancement Provides an enhancement or new feature.
Projects
None yet
Development

No branches or pull requests

3 participants
@biomseed @AbnormalPoof and others