Agent to Player

How do you convert an “agent” type to a “player”? The vehicle event forces an agent and I just want to respawn the player.

    OnAgentExitsVehicle(Agent : agent): void= 
        Print("OnAgentExitsVehicle")

        #agent to player here then will .Respawn() the player
        
3 Likes

player inherits from agent. So you should be able to attempt to cast to player to see if the provided agent is in fact a player instance.

Example:

if (Player := player[Agent]):
    # Do something with Player here now that we know this is in fact a Player type
10 Likes

Thank you!

You can’t convert it, but you can assing it to a ?agent var. For example:

var MaybeAgent : ?agent = false #We declare the ?agent var without passing anything
if (Player := player[Agent]){
    # Do something with Player here now that we know this is in fact a Player type
    set MaybeAgent = option{Agent}}

Having a similar issue, I want to check if the agent who eliminated this creature and if its a player, add a point. What should I do here?

image

Read the error. It should be telling you you have ambiguous definition of Agent. Name your local Agent variable something different to the Agent input parameter. You also need to check your Agent of type ?agent actually exists before trying to use it.

How would I check my Agent of type ?agent?

    Foo(MaybeAgent: ?agent): void =
        if (Agent := MaybeAgent?):
            # Do stuff with 'Agent'

Thanks! I got the following to work with my code:

if(Player := player[Agent?].GetFortCharacter[]):

2 Likes

You can make that:

if(FortCharacter := Agent?.GetFortCharacter[]):

Because GetFortCharacter is available on agent, so there is no need to cast to player. The variable name makes it clear it’s a reference to a fort_character and not a player.

1 Like

Gotcha thx!

Hey i am super lost right now and saw that you understand Agents and verse so i thought i would ask you. I am triing to get the tracker Value only for the the Player playing right now but it switches betwen all players (i only tried it with two) showing my tracked value and the my enemies would be super happy over some help :slight_smile:

this is my code:
OnBegin():void =

    loop: 
        for. Player : (GetPlayspace().GetPlayers())
        do:
            TargetValue := Tracker.GetValue(Player)
            Print("Tracker is at {TargetValue}")