Can't change the state of a player map from a different class

Hey there! I want to change the state of a player map logic in the script in line. 30 & 32, but for some reason the P := Framework.CustomPlayer[Player] causes an error & it doesn’t allow me to set the variable.
Anyone have a clue what the issue could be? :slight_smile:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Colors }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /UnrealEngine.com/Temporary/Diagnostics }

SpawningPads := class(tag){}

# Dancing Tile Class.
TileClass := class<concrete>():
    var Framework : GameFramework = GameFramework{}
    
    @editable Area : mutator_zone_device  = mutator_zone_device{}
    @editable Tile : prop_manipulator_device = prop_manipulator_device{}

    Setup(): void :=
        Area.AgentBeginsEmotingEvent.Subscribe(OnAgentEmoting)

    OnAgentEmoting(Agent:agent): void :=
        Print("@Tile - An agent started emoting.")
        if:
            Player := player[Agent]
            P := Framework.CustomPlayer[Player]
        then:
            set P.HasClaimed = true
            Area.Disable(), Tile.HideProps()
            Print("@Tile - An agent captured a tile succesfully.")

#Custom Music Class.
MusicClass := class<concrete>():
    @editable var Label : string = "Insert Label"
    @editable var Music : audio_player_device = audio_player_device{}

# Custom Player Class.
PlayerClass := class<concrete>():
    var IsPlaying : logic = false
    var HasClaimed : logic = false

# Framework Device Class.
GameFramework := class(creative_device):

    var CustomPlayer : [player]PlayerClass = map{}

    OnBegin<override>()<suspends>: void :=
        TaggedSpawners := GetCreativeObjectsWithTag(SpawningPads{})
        for (TaggedSpawner : TaggedSpawners, Spawner := player_spawner_device[TaggedSpawner]):
                Spawner.SpawnedEvent.Subscribe(OnAgentSpawn)

    OnAgentSpawn(Agent:agent): void :=
        if (Player := player[Agent]):
            OnPlayerSpawn(Player)

    OnPlayerSpawn(Player:player): void :=
        if (Existing := CustomPlayer[Player]){}
        else. if (set CustomPlayer[Player] = PlayerClass{}){}

        Print("@PlayerManager - A player has been setup.")

I can’t find the error here, could you post the error it gives you ?

Sorry for the confusion, it gives out no error, but like P := Framework.CustomPlayer[Player] fails for some reason, so I can’t set a variable from the class! :slight_smile:

Where are you trying to call this from?
You’ll need a way to get to whichever directory you’re trying to work with.
If you want to set the custom player to a variable so you can work with it in local scope from your Framework class you can do something like this:

ArbitraryFunction(Agent:agent):void=
        if (Player:=player[Agent],CustomPlayer:=CustomPlayers[Player]):
            CustomPlayer.FunctionGoesHere()

For other classes that are not directly referenced by your GameManager you can add editables and set the game manager device within those classes.

@editable GameManager:GameFramework = GameFramework {}
#can then call functions of GameManager aka GameFramework from those classes, which then by extension gives you access to CustomPlayer

This works as a 1 way street so however you want to manage references between classes and devices is up to you, and your use case. With CustomPlayer it makes sense to just map it in your original game manager because those classes need to be instantiated to the player. If you were to try to add the game manager back as an editable of the CustomPlayer class though it would create a loop and crash. (as far as I understand)

2 Likes

As Lion says, it seems that you’re editing another GameFramework instance, so you might need to add the @editable attribute.

If this doesn’t work still, can you paste out the code where you set the Framework variable ?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.