Verse Classes Not Running Custom Player Map Functions?

Hello!

I have three classes:

  • A “Device Manager” that is used to handle groups of creative devices and functions that go along with those devices.
  • A “Custom Player” class that maps the individual player stats.
  • A “Game Manager” device that handles all of the classes combined (I have way more that I am using but they are irrelevant to this question.)

My issue is that when I call a function in my “Game Manager” from a “Device Manager” and then try to access a function in my custom player map, the code is never run. (See “HelloWorldFunc” below).

Just to clarify:

  1. I call “HelloWorld” in my general game manager from a device manager. This works great.
  2. After that HelloWorld function is called, I tried to access a function in my custom player map and it never works. I also get no error.

Does anyone know how I can solve this?

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation/Tags }


GameManager := class<unique>(creative_device):
    HelloWorld(Agent : agent):void=return

DeviceManager := class<unique>():
    GameStarted()<suspends>:void=return

spawner := class(tag){}






game_manager := class(GameManager):

    var CustomPlayers : [player]custom_player = map{}

    @editable CustomDevices : []custom_device = array{}



    OnBegin<override>()<suspends>:void=
        GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerLeft)
        InitSpawners()

        for (CD : CustomDevices):
            spawn. CD.GameStarted()



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



    OnPlayerSpawned(Agent : agent):void=
        if (Player := player[Agent]) {InitPlayer(Player)}



    OnPlayerLeft(PlayerLeaving : player):void=
        if (CustomPlayer := CustomPlayers[PlayerLeaving]):
            CustomPlayer.Dispose()
            var NewCustomPlayerMap : [player]custom_player = map{}
            for (Key -> Value : CustomPlayers, Key <> PlayerLeaving):
                set NewCustomPlayerMap = ConcatenateMaps(NewCustomPlayerMap, map{Key => Value})
                set CustomPlayers = NewCustomPlayerMap



    InitPlayer(Player : player):void=
        if:
            Agent := agent[Player]
            Fort := Agent.GetFortCharacter[]
        then:
            if (Existing := CustomPlayers[Player]){}
            else:
                CustomPlayer := custom_player{Player := Player}
                CustomPlayer.Init()
                if (set CustomPlayers[Player] = CustomPlayer) {}





    HelloWorld<override>(Agent : agent):void=
        Print("This will Print")
        if:
            Player := player[Agent]
            CustomPlayer := CustomPlayers[Player]
        then (CustomPlayer.HelloWorldFunc(Agent))











custom_player := class<unique>():

    Player : player



    Init():void=
        Print("This Will Print!")

    Dispose():void=
        Print("This Will Print!")



    HelloWorldFunc(Agent : agent):void=
        Print("This Will Not Print")











#####
##### HERE DOWNWARD WOULD BE A NEW VERSE FILE, ONLY MISSING "using"s
#####


custom_device := class<concrete>(DeviceManager):

    @editable GameManagerEditable : game_manager = game_manager{}

    @editable RandomMutator : mutator_zone_device = mutator_zone_device{}



    GameStarted<override>()<suspends>:void=
        Print("This Will Print!")
        RandomMutator.AgentEntersEvent.Subscribe(RunFunction)

    RunFunction(Agent : agent):void=
        Print("This Will Print!")
        GameManagerEditable.HelloWorld(Agent)
1 Like

So I tried changing the code in my “HelloWorld” function from what is shown above to:

    HelloWorld<override>(Agent : agent):void=
        Print("This will Print")
        if:
            Player := player[Agent]
            CustomPlayer := CustomPlayers[Player]
        then (CustomPlayer.HelloWorldFunc(Agent))
        else:
            Print("Fail")

And it seems like this is where the issue is. The CustomPlayer map is not calling my “HelloWorldFunc” and is failing. Does anyone know why that is?

1 Like

I’ll assume that the “Fail” statement prints, are you sure the InitPlayer function gets called correctly ? (that it gets fired and it calls CustomPlayer.Init())

yep, the Init function gets called correctly, he got pretty much the same code as me from Warforge / this specific video.

1 Like

Whoops! Some amazing creators in the creative discord helped me find the solution to this problem and I forgot to update it here. Ill try to explain this as best I can for anyone else running into a similar issue.

And yes, my CustomPlayer.Init() function was correctly firing and the “Fail” statement was printing.

Essentially what was happening is that the Player was not being found in my custom player map. This was because I had a parent class connected to a child class through an editable and vice verse, creating an infinite loop.

The same issue would occur if placing the same verse device down twice, and using the first device to initialize a player into a custom player map and then trying to run functions in the custom player map using the second device. Because the player was not initialized on the same device the player was not added to that map.

In hindsight this was improper and a messy way of writing the code for this system I am working on but luckily the fix was as simple reorganizing my code (although it took a few days to fully finish that). What works for me was putting all @editables + functions related to those editables in one class and putting the player map and any functions involving the player in another class.

Hopefully I explained this good for anyone having trouble!

Yup, ever since I learned verse a few months ago I have been consistently reusing this code :rofl: It works great!

Verse classes may not run custom player map functions due to compatibility issues, incorrect implementation, or conflicts with other code. Troubleshoot by verifying code integrity and ensuring compatibility with the game engine.