Macro name must be an identifier?

Hi, I’m trying to build a GunGame mode loosely following the sample project. I’m trying to progress to the next gun on a Guard kill (to test) and I’ve found the GuardSpawner’s ‘OnEliminated’ event, but when inputting what I thought would work it throws a ‘Macro name must be an identifier’ error.

I’m sure it’s something that is incredibly basic but my midnight brain can’t seem to think anymore, so any help is welcome :slight_smile:

        # Get all the players in the experience
        AllPlayers := GetPlayspace().GetPlayers()
        for (EliminationGamePlayer : AllPlayers):
            if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
                GuardSpawner.EliminatedEvent.Subscribe(PVEKilled) # subscribe to pve eliminated

                # Event that handles when a guard is eliminated
    PVEKilled(Result:device_ai_interaction_result):void=                    
        Print("Guard Killed")                                               # PRINTS DEBUG LINE
        Killer := Result.Source                                             # DEFINES SOURCE OF GUARD DEATH
        if (FortCharacter := Killer?):
            GrantNextWeapon(Killer{agent})                                  # GRANTS NEXT WEAPON

This syntax doesn’t exist, what are you trying to do here ? I think GrantNextWeapon(Killer) would work better

Hi, I was trying to grant the next weapon to the player who killed the guard.

I believe I’ve sorted it (tested in-game and it worked)

What I did was the following:

    PVEKilled(Result:device_ai_interaction_result):void=
        Print ("Guard Killed")
        Killer := Result.Source
        if (FortCharacter := Killer?):
                GrantNextWeapon(FortCharacter)

The thing I’m unsure of now is whether that would give the next weapon to all players, or just the one who killed the guard.

Also with regards to your suggestion, putting just GrantNextWeapon(Killer) throws an error of “This function parameter expects a value of type agent, but this argument is an incompatible value of type ?agent.”.

Thanks!

What’s the GrantNextWeapon function signature ? It should take a player or agent reference, not a ?agent or fort_character one

Here’s the code for the GrantNextWeapon fuction (from the Verse Elimination Sample page):

                  # Check if there is a winner for the game, if not then grant the next weapon
    GrantNextWeapon(Agent:agent):void=
        if (var CurrentItemNumber:int = AgentMap[Agent]):
            if (IsVictoryConditionMet(CurrentItemNumber) = true):
                EndGame(Agent) # Game has been won
            else: # Game is not over yet
                set CurrentItemNumber = CurrentItemNumber + 1
                if (ItemGranter := WeaponItemGranters[CurrentItemNumber - 1]):
                    ItemGranter.GrantItem(Agent)
                
                if (set AgentMap[Agent] = CurrentItemNumber) {}

Apologies, but I’m very new to this and hope that contains the info you asked for.

The code all works for a player v player elimination (not shown in code examples given), I just wanted to have it count for PvE enemies too for testing purposes.

This is bad, it shouldn’t be a global value, but a player value, like the player map you’re using below

It should give the weapon only to the player like this, but you have to look at the granting method inside the item granter just to be sure, if it’s set to All/Everyone it’s going to give it to everyone nonetheless

I got confused here, because your FortCharacter variable is not a fort_character type, but an agent one, so you should be fine