Ok, so first thing, there is a Style Guide and following it will make your code more readable as you read it, and more readable to others when they read it.
Case in point, Enum should always be PascalCase. Because when I’m reading your code, that lack of PascalCase had me scratching my head. Not the end of the world, but still - helpful.
So let’s rework your Enum. The name should be in PascalCase, and it’s just a list of things it could be not what it is. Also, we are going to put each entry on its own line for readability. Notice the last line is followed by a comma. It’s not needed, but if you add a new line, you don’t have to add it later.
Then we are going to add a goal (lowercase) variable to store the value for the player. When we declare the variable, we are going to say it is of type Goal, which means it has to have one of those Enums as a value and nothing else. This helps us find bugs. If we pass it the wrong thing, we get an error.
#player.gd
enum Goal {
SAVE_YOUR_LOVED_ONE,
BUY_YOUR_FREEDOM,
GET_YOUR_SHIP_BACK,
}
var goal: Goal
Next let’s take a look at your character creation script. You have three things going on, and it’s a bit convoluted.
First we are going to turn off all three descriptions, then turn on the one we want. This gets rid of all your if/else statements. However, if you can, just go into your scene, hide them all and remove those 3 lines. If that’s not possible, no sweat.
Then, let’s use a match statement. It will be easier to read.
Finally I’m skipping assigning a local goal variable, and assigning it right to the player instance, but the last line will also set a local version of the variable if you need it for some reason (though you should just read it from player.goal)
#character_creation.gd
@export var trader: Trader
func _on_goal_list_item_selected(chosen_goal) -> void:
button_next_from_goal.visible = true
goal_desc_save.visible = false
goal_desc_buy.visible = false
goal_desc_get.visible = false
match(chosen_goal):
0:
goal_desc_save.visible = true
trader.goal = trader.Goal.SAVE_YOUR_LOVED_ONE
1:
goal_desc_buy.visible = true
trader.goal = trader.Goal.BUY_YOUR_FREEDOM
2:
goal_desc_get.visible = true
trader.goal = trader.Goal.GET_YOUR_SHIP_BACK
goal = trader.goal #If you need it
As you can see, if you can hide those descriptions in the editor and remove the local goal variable, the code gets even more concise.