This function parameter expects a value of type agent->void, but this argument is an incompatible value of type type{_(:agent)<decides>:void}

I m trying to setText as players name(i have them in array) on 12 independent Loud_buttons using index

For Example:

PlayerName[0] for button1 but it says

[This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.(3512)]

What I have tried so far is as follows :

1:Used on OpenUI Function // it had following properties called in it

   FetchTeamPlayers()

   UI.AddUI[PlayerAgent]

   GetPlayerName()

   UI.GetHUI()

But Than

T_Button.InteractedWithEvent.Subscribe(OpenUI)

started having issues that it cant take decide function

2:Made Separate fucntion TO setText With Decide Effect to abstract it directly from .Subscribe thing

(obviously than called it in OpenUI)

like

OpenUI(PlayerAgent: agent): void =
{
FetchTeamPlayers()

    UI.AddUI[PlayerAgent]

    GetPlayerName()

    UI.GetHUI()

    SetBText[]      
    
}

still it wants me to add decide effect on it so now i m stuck with an error on T_Button.InteractedWithEvent.Subscribe(OpenUI) that says

This function parameter expects a value of type agent->void, but this argument is an incompatible value of type type{_(:agent):void}.(3509)

Any Help Or Solution will be highly appreciated

Hello @ISPR_Matti ! How are you?

The error is because you are trying to use functions that have the effect in contexts where it is not allowed. The effect means that the function may fail and needs to be handled in a context that can deal with that failure.

For example, “GetPlayerName()” could fail, so you cannot call it directly. You need to handle it inside an “if” like this:

    if (PlayerName := GetPlayerName[]):
        Print("Player Name: {PlayerName}")

First you add the Player Name to a variable “PlayerName” inside the “if”, and then you can store that PlayerName in an array or set it to the corresponding button if you want.

Regarding the error with “This function parameter expects a value of type agent->void, but this argument is an incompatible value of type type{_(:agent):void}.(3509)” it is really weird because the Button Device returns an Agent, so it should fail if you are using that device and your function with “Agent : agent”. It would be really usefull to see the rest of the code so I can replicate it and check it.

Hope this helps!