PlayerSpawned event doesnt seem to pass an agent

I am trying to subscribe the playerspawned event to call the function check level, which takes in a player and calls the checklevel function in the level_manager file. The level_manager file takes the agent in, gets the level from the table, then calls the item granter based on that level to give the player items. Everything works except the GiveItem() function which always fails. I don’t understand what is wrong. My only idea is putting the check level and item granters into the same file. Are you not able to pass the player to a different file in verse?

player_manager file

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
player_manager := class(creative_device):

    PlayerStatsManager:player_stats_manager = player_stats_manager{} #Creates an instance of class so can use methods
    PlayerLevelManager:level_manager = level_manager{}

    @editable
    MonsterElimXP:float = 0.3

    @editable
    PlayerElimXP:float = 0.0

    @editable
    MonsterSpawners: []creature_spawner_device = array{}

    @editable
    PlayerSpawnersArray:[]player_spawner_device=array{}


    

 # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
         
        for(spawner : PlayerSpawnersArray):
            spawner.SpawnedEvent.Subscribe(CheckLevel)
            Print("Intialized Spawner")
       

        #Initialize Current Players
        PlayersArray := GetPlayspace().GetPlayers()
        PlayerStatsManager.InitializeAllPlayers(PlayersArray)

        GetPlayspace().PlayerAddedEvent().Subscribe(PlayerStatsManager.InitializePlayer)

        

        #Display all stats (DEBUG)
        for(p:PlayersArray):
            DisplayStats(p)
            PlayerLevelManager.CheckLevel(p)
            Print("Initial Level check and Grant")
            PlayerStatsManager.SetLevel(p,0) #Change this in full
        
        
        
       <#Connect all the creature spawners
       for(spawners : MonsterSpawners):
            spawners.EliminatedEvent.Subscribe(OnMonsterElim)
            Print("Creature Spawner connected")
    #>
   <#
    OnMonsterElim(Result:device_ai_interaction_result):void = 
        
        if:
            Agent := Result.Source?
            Player := player[Agent]
            CurrentXP := PlayerStatsManager.GetXP[Player]
            
        then:
            Print("Current XP is {CurrentXP}")
            PlayerStatsManager.AddXP(Player,MonsterElimXP)
            Print("Added {MonsterElimXP}")
            PlayerLevelManager.CheckLevel(Player)
            #CheckLevel(Player)  #Anytime XP is added, check level
        else:
            Print("The creature was not killed by a player, or unsuccessful lookup")
#>
    DisplayStats(Player:player):void=
        if:
            pXP := PlayerStatsManager.GetXP[Player]
            pLevel := PlayerStatsManager.GetLevel[Player]
            pWins := PlayerStatsManager.GetWins[Player]
        then:
            Print("XP = {pXP}")
            Print("Level = {pLevel}")
            Print("Wins = {pWins}")


    CheckLevel(Agent: (agent)):void=
        if: 
            Player := player[Agent]
        then:
            Print("Checking players level from player_manager")
            PlayerLevelManager.CheckLevel(Player)
            Print("Called check level from player_manager")
        else:
            Print("Agent was not a player")
            


level_manager file

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
level_manager := class(creative_device):


    PlayerStats:player_stats_manager = player_stats_manager{}

    
    Level1XP: float = 1.0

    Level2XP: float = 3.0

    Level3XP: float = 7.0

    Level4XP: float = 11.0

    Level5XP: float = 16.0

    Level6XP: float = 20.0
    
    Level7XP: float = 35.0

    Level8XP: float = 50.0
    
    Level9XP: float = 80.0
 
    Level10XP: float = 100.0
    
    @editable
    ItemGranters:[]item_granter_device = array{}

   

    
    GiveItem(Agent:agent, Level:int):void = 
        if: 
            Print("Entering if statement")
            Player := player[Agent]
            Print("Checked if player was agent")
            Granter:=ItemGranters[Level]
        then:
            Granter.GrantItem(Player)
        else:
            Print("Agent was not a player (GiveItem)")

    CheckLevel(Player:player):void=
        if:
            PlayerXP := PlayerStats.GetXP[Player]  #Get players XP
            Print("Checking Player Level in level_manager")
        then:  
            if(PlayerXP < Level1XP):
                PlayerStats.SetLevel(Player, 0)
                GiveItem(Player,0)

            if(PlayerXP >= Level1XP and PlayerXP < Level2XP):
                PlayerStats.SetLevel(Player, 1)
                GiveItem(Player,1)

            if(PlayerXP >= Level2XP and PlayerXP < Level3XP):
                PlayerStats.SetLevel(Player, 2)
                GiveItem(Player,2)

            if(PlayerXP >= Level3XP and PlayerXP < Level4XP):
                PlayerStats.SetLevel(Player, 3)
                GiveItem(Player,3)

            if(PlayerXP >= Level4XP and PlayerXP < Level5XP):
                PlayerStats.SetLevel(Player, 4)
                GiveItem(Player,4)

            if(PlayerXP >= Level5XP and PlayerXP < Level6XP):
                PlayerStats.SetLevel(Player, 5)
                GiveItem(Player,5)

            if(PlayerXP >= Level6XP and PlayerXP < Level7XP):
                PlayerStats.SetLevel(Player, 6)
                GiveItem(Player,6)

            if(PlayerXP >= Level7XP and PlayerXP < Level8XP):
                PlayerStats.SetLevel(Player, 7)
                GiveItem(Player,7)

            if(PlayerXP >= Level8XP and PlayerXP < Level9XP):
                PlayerStats.SetLevel(Player, 8)
                GiveItem(Player,8)

            if(PlayerXP >= Level9XP and PlayerXP < Level10XP):
                PlayerStats.SetLevel(Player, 9)
                GiveItem(Player,9)

            if(PlayerXP >= Level10XP):
                PlayerStats.SetLevel(Player, 10)
                GiveItem(Player,10)
        else:
            Print("Unable to check level in level_manager")
                
            

Hi.
It is puzzling. The code is well written.

I was just curious when the Item Granter is called, why is the player type being sent? Doesn’t it take in an agent?

Granter.GrantItem(Player)

If you sent in the agent type, then there would be no need for the cast from Agent to Player in the preceding IF expression.

That’s the only thing I had a question about.

Yeah I tried both methods passing a player and an agent, this code was just when I tried using only the player type to see if it would work. The issue I was facing was no matter what the if statement would always fail indicating a player was not given. I found just moving it to the same file ended up fixing all my issues. So it seems like passing the agent between files isn’t supported. The next issue I’m coming across is every time the player is granted an item it dismounts them from their driftboard and destroys it for some reason.