Trigger on player

I’m trying to have a trigger return the player, but it’s not working. I have the var for fort character and that being set on Find player called at begin play. The issue I have is the subscribe thing isn’t happy and I can’t work out why.

If I do a ? in the below before fort the code is kind of happy except for the SetVulnerability. that then isn’t happy.
var MaybeFortCharacter : fort_character = false

Any idea would be amazing because it’s causing headaches with this verse code. C++ is actually better etc then this code language.

    
    var MaybePlayer<private>:?player = false
    var MaybeFortCharacter : fort_character = false
    Logger<private>:log = log{Channel := log_SecretAgent}
    
    
    @editable
    Trigger:trigger_device = trigger_device{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        # TODO: Replace this with your code
        Print("Begin Play Triggered")
        FindPlayer()

        Trigger.TriggeredEvent.Subscribe(PlayerInZone)
        
        
        

    FindPlayer<public>():void =
        if (Player := GetPlayspace().GetPlayers()[0], FortCharacter := Player.GetFortCharacter[]):
            set MaybeFortCharacter = option{FortCharacter}
            set MaybePlayer = option{Player}
        

    PlayerInZone(FortCharacter:fort_character):void =
        MaybeFortCharacter.SetVulnerability(false)

Yup you’ve got the right idea. Basically you do need the ? before fort_character, because it’s an “option”, which means it can either have a value, or be “false”.

When you call SetVulnerability on it, verse doesn’t know whether it’s actually the fort_character or just “false” at that point, so you first have to make sure it’s a real fort character. To do that, you just assign it to a constant, but this time use a ? after it, like this:

if(FortCharacter := MaybeFortCharacter?):
	FortCharacter.SetVulnerability(false)

To write this a shorter way, you can also do:

if((MaybeFortCharacter?).SetVulnerability(false)):

Amazing thank you, I was trying to think in terms fo casting like in C++ that you would do. :slight_smile: