Anyone know what’s wrong with this code?

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }

PlayerStats := class():
var Eliminations : int = 0
var Deaths : int = 0

AddElim(i : int): void =
    set Eliminations += i

AddDeath(i : int): void =
    set Deaths += i

GetElimCount(): int =
    return Eliminations

spawner := class(tag){}

KillsTextUI(InText : string) : message = “Kills: {IntText}”

Kill_Counter_Device := class(creative_device):

var playerMap : [player]PlayerStats = map{}

InitSpawners():void=
Spawners := GetCreativeObjectsWithTag(spawner{})
for (Obj : Spawners):
if (Spawner := player_spawner_device[Obj]):
Spawner.SpawnedEvent.Subscribe(OnPlayerAdded)

OnBegin<override>()<suspends>:void=
InitSpawners()
GetPlayerspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)

OnPlayerAdded(NewPlayer : agent): void =
if (PlayerObj := player[NewPlayer]):
if (PlayerExists := playerMap[NewPlayer]):

    else:
        if(set playerMap[PlayerObj] = PlayerStats{}):
            if(AgentStats := playerMap[PlayerObj]):
                Print("Player Kills: {AgentStats.GetElimCount()}")
                if (FortChar:fort_character := NewPlayer.GetFortCharacter[]):
                    FortChar.EliminatedEvent().Subscribe(OnEliminated)
                    var UIButton : button_load = button_loud{}
                    if (PlayerUi := GetPlayerUI[PlayerObj]):
                        MyCanvas : canvas = canvas:
                            Slots := array:
                                canvas_slot:
                                    Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
                                    Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                                    Alignment := vector2{X := 0.5, Y := 0.5}
                                    SizeToContent := true
                                    Widget := UIButton
                        PlayerUi.AddWidget(MyCanvas)
                        UIButton.SetText(KillsTextUI("{AgentStats.GetElimCount()}"))

OnEliminated(Result:elimination_result): void =
Eliminator := Result.EliminatingCharacter
Eliminated := Result.EliminatedCharacter
if (FortCharacter := Eliminator?, EliminatorAgent := FortCharacter.GetAgent):
AddElimination(EliminatorAgent)
if (FortCharacter := Eliminated, EliminatedAgent := FortCharacter.GetAgent):
AddDeath(EliminatedAgent)

AddElimination(Agent : agent): void =
if(PlayerObj := player[Agent]):
if(AgentStats := playerMap[PlayerObj]):
var UIButton : button_loud = button_loud{}
if (PlayerUi := GetPlayerUI[PlayerObj]):
MyCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X :=0.5, Y := 0.0}}
Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
Alignment := vector2{X := 0.5, Y := 0.5}
SizeToContent := true
Widget := UIButton
PlayerUi.AddWidget(MyCanvas)
AgentStats.AddElim(1)
UIButton.SetText(KillsTextUI(“{AgentStats.GetElimCount()}”))

AddDeath(Agent : agent): void =
if(PlayerObj := player[Agent]):
if(AgentStats := playerMap[PlayerObj]):
AgentStats.AddDeath(1)

OnPlayerRemoved(PlayerLeave : player): void =
if(ActualPlayer := playerMap[PlayerLeave]):
var TempPlayerMap: [player]PlayerStats = map{}
for (Key → Value : playerMap, Key <> PlayerLeave):
set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key => Value})

    set playerMap = TempPlayerMap

I’m getting an error on the line OnBegin():void=

It’s hard to read

try change OnBegin<override>()<suspends>:void= to OnBegin()<override><suspends>: void =

1 Like

I cleaned up the indentation a little bit and made a few changes. Here is a compliable iteration, interesting to note the JSON import, my IntelliSense showed me that- first time seeing it.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/JSON }

PlayerStats := class():
    var Eliminations : int = 0
    var Deaths : int = 0
    
    AddElim(i : int): void =
        set Eliminations += 1
    AddDeath(i : int): void =
        set Deaths += 1
    GetElimCount(): int =
        return Eliminations


KillsTextUI<public><localizes>(InText : string) : message = "{value}"


Kill_Counter_Device := class(creative_device):

    
    @editable
    Spawners : []player_spawner_device = array{}
    var playerMap : [player]PlayerStats = map{}
    
    
    InitSpawners():void=
        for (Spawner : Spawners):
            Spawner.SpawnedEvent.Subscribe(OnPlayerAdded)

    OnBegin<override>()<suspends>:void=
        InitSpawners()
        GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
    
    OnPlayerAdded(NewPlayer : agent): void =
        if (PlayerObj := player[NewPlayer]):
            if (PlayerExists := playerMap[NewPlayer]):
            else:
            if(set playerMap[PlayerObj] = PlayerStats{}):
            if(AgentStats := playerMap[PlayerObj]):
                        Print("Player Kills: {AgentStats.GetElimCount()}")
                if (FortChar:fort_character := NewPlayer.GetFortCharacter[]):
                    FortChar.EliminatedEvent().Subscribe(OnEliminated)
                var UIButton : button_loud = button_loud{}
                if (PlayerUi := GetPlayerUI[PlayerObj]):
                        MyCanvas : canvas = canvas:
                            Slots := array:
                                canvas_slot:
                                    Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
                                    Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                                    Alignment := vector2{X := 0.5, Y := 0.5}
                                    SizeToContent := true
                                    Widget := UIButton
                        PlayerUi.AddWidget(MyCanvas)
                UIButton.SetText(KillsTextUI("{AgentStats.GetElimCount()}"))

    OnEliminated(Elimination:elimination_result): void =
        Print("Elimination event") 
        if(Killer := Elimination.EliminatingCharacter?, KillerAgent := Killer.GetInstigatorAgent[]):
            AddElimination(KillerAgent)
        if(Killed := Elimination.EliminatedCharacter, KilledAgent := Killed.GetInstigatorAgent[]):
            AddDeath(KilledAgent)
    
    AddElimination(Agent : agent): void =
        if(PlayerObj := player[Agent]):
            if(AgentStats := playerMap[PlayerObj]):
                AgentStats.AddElim(1)
                
                var UIButton : button_loud = button_loud{}
                if (PlayerUi := GetPlayerUI[PlayerObj]):
                        MyCanvas : canvas = canvas:
                            Slots := array:
                                canvas_slot:
                                    Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X :=0.5, Y := 0.0}}
                                    Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                                    Alignment := vector2{X := 0.5, Y := 0.5}
                                    SizeToContent := true
                                    Widget := UIButton
                        PlayerUi.AddWidget(MyCanvas)
                UIButton.SetText(KillsTextUI("{AgentStats.GetElimCount()}"))

    AddDeath(Agent : agent): void =
        if(PlayerObj := player[Agent]):
            if(AgentStats := playerMap[PlayerObj]):
                AgentStats.AddDeath(1)

    OnPlayerRemoved(PlayerLeave : player): void =
        if(ActualPlayer := playerMap[PlayerLeave]):
        var TempPlayerMap: [player]PlayerStats = map{}
            for (Key -> Value : playerMap, Key <> PlayerLeave):
                set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key => Value})
                set playerMap = TempPlayerMap
1 Like

If I’m not mistaken, <suspends> specifier is contagious, meaning it can only call other functions marked as such. In your case InitSpawners would also need to be <suspends>. If that’s not the issue then could you provide the error message? On second thought, I doubt this is the issue since you’re calling function is not async, but it’s worth a try.

That or in your for loop inside InitSpawners shouldn’t it be for (Obj := Spawners)?

Verse documentation is somewhat lacking on these rules because the examples are so inconsistent and don’t always follow the Verse style guides.
Ultimately a specific error message would be much more helpful for us.

1 Like