How do I order contents in a scroll wheel

Godot Version

Version 4.3

Question

I’m trying to make a scroll wheel that allows for the filtering of its content depend on what is being clicked. For example the overall of a player or there age.

This is what it looks like currently →

If anyone knows of how to do or of any helpful videos for ordering the children it would be much appreciated.

You can make use of Array.sort_custom() method.
Assuming your Player class is something like that:

# Player.gd
class_name Player
extends Resource

@export var name: String
@export var age: int
@export var overall: int
@export var country: String

you can store all your Players in an array in some global Autoload class and have a function to sort the array by age and overall.

# GameManager.gd autoload
extends Node

@export var players: Array[Player]

func sort_players_by_age() -> void:
	players.sort_custom(func(player1: Player, player2: Player): return player1.age < player2.age)

func sort_players_by_overall() -> void:
	players.sort_custom(func(player1: Player, player2: Player): return player1.overall< player2.overall)

Then, you can use one of these sort functions before you populate your ScrollContainer (I’m assuming that’s what you use to hold your players), e.g. by changing the sort_type variable.

# ScrollContainer.gd
extends ScrollContainer

enum SortType {
BY_AGE,
BY_OVERALL,
}

var sort_type: SortType

func populate_container() -> void:
	match sort_type:
		SortType.BY_AGE:
			GameManager.sort_players_by_age()
		SortType.BY_OVERALL:
			GameManager.sort_players_by_overall()
	for player: Player in GameManager.players:
		# your code of populating the ScrollContainer
1 Like