This function parameter expects a value of type agent->void, but this argument is an incompatible value of type ?agent->void.

I am not sure how I can fix this error in my code. This is for the tracker device, I am trying to have it register as an elimination/ promotion in my gun game when users eliminate a guard in the map

1 Like

TestPlayerElimination(Agent : agent): void=

2 Likes

Did you get this figured out?

hello did you figure it out ??

Figured out the issue after coming here for a quick google search.

Let me give a basic rundown. My usage involved listening to when a sentry was eliminated, and playing a custom sound based off of this event firing. The sentry class has a listenable .EliminatedEvent, that can be .Subscribe() to. The problem arrises with the parameters the method expects.

The error clearly states that the method is expecting a type of ?agent to be fed in, but its being fed in agent. What does this mean? The ? syntax denotes an optional value. Why is agent optionable here? Because an agent doesnt necessarily have to be the instigator of the elimination.

So if I have a method called “BotElimSound” that I want to play when a sentry is eliminated, I subscribe it like so

    sentry.EliminatedEvent.Subscribe(BotElimSound)

But in the definition of BotElimSound, I must define the agent param being passed in as an optional.

``
`

BotElimSound (Agent:?agent) : void =
fullElimSound.Play()

Notice the ? before the agent type, this makes agent optional, which will fix your error.

2 Likes

Actually your problem is the opposite issue, so you just gotta remove the ? from your method definition. This is because the Guard.CompletedEvent can only be instigated by an agent, therefore it is impossible to pass an ?agent to it. Which is what you define as possible in your “TestPlayerElimination(Agent: ?agent)” method by having the ? before the agent type.