Dearest all!
I got a bit too adventurous with Verse: I’m building a podium-leaderboard:
I’m trying to
- Use Player Reference Devices to create a podium displaying the three players with most eliminations
- sort players by eliminations
- update the leaderboard at each kill
This is the last iteration of the code… and I’m getting quite humbled by the experience ![]()
Any help would be greatly appreciated!
using { /Fortnite.com/Devices } # Importing necessary modules for devices
using { /Verse.org/Simulation } # Importing necessary modules for simulation
using { /UnrealEngine.com/Temporary/Diagnostics } # Importing necessary modules for diagnostics
using { /Fortnite.com/Characters } # Importing necessary modules for characters
using { /Fortnite.com/Game } # Importing necessary modules for game
# EN_Podium : Class to manage the winner podium
winner_podium := class(creative_device):
@editable
PlayerReference1 : player_reference_device = player_reference_device{} # Editable player reference device 1
@editable
PlayerReference2 : player_reference_device = player_reference_device{} # Editable player reference device 2
@editable
PlayerReference3 : player_reference_device = player_reference_device{} # Editable player reference device 3
var PlayerEliminations : [agent]int = map{} # Map to keep track of player eliminations
# Event to handle when the device starts
OnBegin<override>()<suspends>:void=
if (Playspace := GetPlayspace()): # Get the playspace (no square brackets as it doesn't have the 'decides' effect)
if (AllPlayers := Playspace.GetPlayers()): # Get all players in the playspace (no square brackets as it doesn't have the 'decides' effect)
for (Player : AllPlayers): # Iterate over all players
if (FortCharacter := Player.GetFortCharacter[]): # Get the fort character of the player (square brackets as it has the 'decides' effect)
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # Subscribe to the eliminated event
# Function to handle player eliminations
OnPlayerEliminated(Result:elimination_result):void=
if (EliminatingCharacter := Result.EliminatingCharacter?): # Check if there is an eliminating character
if (EliminatingAgent := EliminatingCharacter.GetAgent[]): # Get the agent of the eliminating character (square brackets as it has the 'decides' effect)
if (EliminationCount := PlayerEliminations[EliminatingAgent]): # Check if the agent is already in the map
set PlayerEliminations[EliminatingAgent] = EliminationCount + 1 # Increment the elimination count
else:
set PlayerEliminations[EliminatingAgent] = 1 # Initialize the elimination count
UpdatePlayerReferences() # Update the player references
# Function to update the player reference devices
UpdatePlayerReferences():void=
var PlayerList:[]tuple(agent, int) = for {Agent -> Eliminations : PlayerEliminations} do {Agent, Eliminations} # Create a list of players and their eliminations
SortPlayerList(PlayerList) # Sort the player list by eliminations
if (PlayerList.Length >= 1): # Check if there is at least one player
PlayerReference1.SetPlayer(option{PlayerList[0][0]}) # Set the first player reference
if (PlayerList.Length >= 2): # Check if there are at least two players
PlayerReference2.SetPlayer(option{PlayerList[1][0]}) # Set the second player reference
if (PlayerList.Length >= 3): # Check if there are at least three players
PlayerReference3.SetPlayer(option{PlayerList[2][0]}) # Set the third player reference
# Function to sort the player list by eliminations
SortPlayerList(PlayerList:[]tuple(agent, int)):void=
var Swapped:logic = false # Variable to track if a swap was made
for (I := 0..PlayerList.Length - 1): # Outer loop for bubble sort
set Swapped = false # Reset the swapped variable
for (J := 0..PlayerList.Length - I - 2): # Inner loop for bubble sort
if (PlayerList[J][1] < PlayerList[J + 1][1]): # Compare the eliminations
Temp := PlayerList[J] # Swap the elements
set PlayerList[J] = PlayerList[J + 1] # Swap the elements
set PlayerList[J + 1] = Temp # Swap the elements
set Swapped = true # Set the swapped variable to true
if (not Swapped): # If no swaps were made, the list is sorted
break # Exit the loop```
these are the errors so far:
{
"code": "3513",
"severity": 8,
"message": "Expected an expression that can fail in the ‘if’ condition clause",
"startLineNumber": 20
},
{
"code": "3513",
"severity": 8,
"message": "Expected an expression that can fail in the ‘if’ condition clause",
"startLineNumber": 21
},
{
"code": "3512",
"severity": 8,
"message": "This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.",
"startLineNumber": 31
},
{
"code": "3512",
"severity": 8,
"message": "This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.",
"startLineNumber": 33
},
{
"code": "3506",
"severity": 8,
"message": "Unknown member SetPlayer in player_reference_device.",
"startLineNumber": 42
},
{
"code": "3506",
"severity": 8,
"message": "Unknown member SetPlayer in player_reference_device.",
"startLineNumber": 44
},
{
"code": "3506",
"severity": 8,
"message": "Unknown member SetPlayer in player_reference_device.",
"startLineNumber": 46
},
{
"code": "3511",
"severity": 8,
"message": "Tuple element access uses round brackets / parentheses MyTuple(Idx) rather than square [] or curly {} brackets.",
"startLineNumber": 54
},
{
"code": "3511",
"severity": 8,
"message": "Tuple element access uses round brackets / parentheses MyTuple(Idx) rather than square [] or curly {} brackets.",
"startLineNumber": 54
},
{
"code": "3512",
"severity": 8,
"message": "This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.",
"startLineNumber": 55
},
{
"code": "3512",
"severity": 8,
"message": "This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.",
"startLineNumber": 56
},
{
"code": "3509",
"severity": 8,
"message": "The assignment’s left hand expression type tuple(agent,int) cannot be assigned to",
"startLineNumber": 56
},
{
"code": "3512",
"severity": 8,
"message": "This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.",
"startLineNumber": 57
},
{
"code": "3509",
"severity": 8,
"message": "The assignment’s left hand expression type tuple(agent,int) cannot be assigned to",
"startLineNumber": 57
},
{
"code": "3513",
"severity": 8,
"message": "Expected an expression that can fail in the operand of ‘not’",
"startLineNumber": 59
},
{
"code": "3581",
"severity": 8,
"message": "This break is not in a breakable context. break may currently only be used inside a loop.",
"startLineNumber": 60
}```
**Thank you in advance for grinding with me! :D**


