Skip to content

Enhancement: Null coalescing support for HScript #3767

Closed
@AbnormalPoof

Description

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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: resolved internallyCompleted development and will be released some time in the future.topic: modsRelated to the creation or use of mods.type: enhancementInvolves an enhancement or new feature.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions