# Problem with Subscribe

**URL:** <https://forums.unrealengine.com/t/problem-with-subscribe/832398>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 29, 2023, 4:21pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398 "2023-03-29T16:21:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walper159](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/walper159/32/640974_2.png) [@Walper159](https://forums.unrealengine.com/u/Walper159)\
**Post date:** [March 29, 2023, 4:21pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398/1 "2023-03-29T16:21:41Z")

</div>

I’m trying to connect the function in UEFN using a susbcribe, but I can’t do it, it tells me that “this funtion parameter expects a value of type agent-\>void, but this argument is incompatible value of type void”.  
Is there a way to subscribe the function?

These are the line that mark error

`ActionMenu.InteractedWithEvent.Subscribe(OpenActionMenu) for (Selector : Selectors) { Selector.InteractedWithEvent.Subscribe(StartCompleteAction)`

Here is the full script

```auto
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /Fortnite.com/Characters}

action_device := class(creative_device):

    @editable
    ActionMenu:button_device = button_device{}
    @editable
    Selectors:[]button_device = array{}
    @editable
    ValidFx:[]vfx_spawner_device = array{}

    var Canvas:?canvas = false

    OnBegin<override>()<suspends>:void = {

        ActionMenu.InteractedWithEvent.Subscribe(OpenActionMenu)
        for (Selector : Selectors) {
        Selector.InteractedWithEvent.Subscribe(StartCompleteAction)
        }
    }

    StartCompleteAction(Player:player): void =
       spawn { CompleteAction() }
       return 

    CompleteAction()<suspends>:void = {
        for (Fx : ValidFx) { Fx.Disable() }
        for (Selector : Selectors) { Selector.Disable() }
        Sleep(2.0)
        ActionMenu.Enable()
        return 
    }

    OpenActionMenu(Player:player):void = {
        Print("Button Interacted With!")
        if (PlayerUI := GetPlayerUI[Player]) {
            if (TmpCanvas := Canvas?) {
                Print("Removing Canvas")
                PlayerUI.RemoveWidget(TmpCanvas)
                set Canvas = false
            } else {
                ActionMenu.Disable()
                Print("Create New Canvas")
                NewCanvas := MakeCanvas()
                # Add the canvas and set input mode to UI (ie mouse controls cursor and not game)
                PlayerUI.AddWidget(NewCanvas, player_ui_slot{ InputMode := ui_input_mode.All })
                set Canvas = option{NewCanvas}
            }
        }
        return
    }

    MoveForUICanvas<localizes>:message:= "Move"
    AttackForUICanvas<localizes>:message := "Atttack"
    CancelForUICanvas<localizes>:message := "Cancel"

    MakeCanvas():canvas = {
        Move:button_loud=button_loud{ DefaultText := MoveForUICanvas }
        Attack:button_regular=button_regular{ DefaultText := AttackForUICanvas }
        Cancel:button_quiet=button_quiet{ DefaultText := CancelForUICanvas }
        Move.OnClick().Subscribe(MoveSelected)
        Attack.OnClick().Subscribe(AttackSelected)
        Cancel.OnClick().Subscribe(CancelSelected)
        NewCanvas := canvas:
            Slots := array:
                canvas_slot:
                    Anchors := anchors{ Maximum:= vector2{X:=1.0, Y:=1.0} }
                    Offsets := margin{ Top:=100.0, Left:=100.0, Right:=100.0, Bottom := 100.0 }
                    Widget := stack_box:
                        Orientation := orientation.Vertical
                        Slots := array:
                            stack_box_slot:
                                Widget := Move
                            stack_box_slot:
                                Widget := Attack
                            stack_box_slot:
                                Widget := Cancel
        return NewCanvas
    }

    MoveText<localizes>:message := "Moving"

    MoveSelected(Message:widget_message):void = {
        Print("Move Selected")
        if (Button := text_button_base[Message.Source]) {
            Button.SetText(MoveText)
        }

        for (Selector : Selectors) { Selector.Enable() }
        for (Fx : ValidFx) { Fx.Enable() }

        if (TmpPlayerUI := GetPlayerUI[Message.Player], TmpCanvas := Canvas?) {
            TmpPlayerUI.RemoveWidget(TmpCanvas)
            set Canvas = false
        }
        return
    }

    AttackText<localizes>:message := "Ataque no ha sido implementado"

    AttackSelected(Message:widget_message):void = {
        Print("Attack Selected")
        if (Button := text_button_base[Message.Source]) {
            Button.SetText(AttackText)
            Button.SetEnabled(false)
        }
        return
    }

    CancelText<localizes>:message :="Mensaje Recibido C"
    
    CancelSelected(Message:widget_message):void = {
        Print("Cancel Clicked")
        ActionMenu.Enable()
        # Test remove the whole canvas in response to a click
        if (TmpPlayerUI := GetPlayerUI[Message.Player], TmpCanvas := Canvas?) {
            TmpPlayerUI.RemoveWidget(TmpCanvas)
            set Canvas = false
        }
        if (Button := text_button_base[Message.Source]) {
            Button.SetText(CancelText)
        }
        return
    }

```

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [March 29, 2023, 4:40pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398/2 "2023-03-29T16:40:39Z")

</div>

A `player` type is also an `agent` type, so just change the type in your callbacks to be of type `agent`.

```auto
OpenActionMenu(Player:agent):void =
StartCompleteAction(Player:agent): void =

```

---

<div class="post-metadata">

**Author:** ![Walper159](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/walper159/32/640974_2.png) [@Walper159](https://forums.unrealengine.com/u/Walper159)\
**Post date:** [March 29, 2023, 4:58pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398/3 "2023-03-29T16:58:50Z")

</div>

Wow, that worked although now in `if (PlayerUI := GetPlayerUI[Player])` I already changed it to [Agent] but it still doesn’t work and expects a tuple variable, but it still worked. Thanks

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [March 29, 2023, 5:01pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398/4 "2023-03-29T17:01:49Z")

</div>

You can also cast an `agent` as a `player` type like this:  
`if (PlayerUI := GetPlayerUI[player[Player]]):`

---

<div class="post-metadata">

**Author:** ![Walper159](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/walper159/32/640974_2.png) [@Walper159](https://forums.unrealengine.com/u/Walper159)\
**Post date:** [March 29, 2023, 5:05pm UTC](https://forums.unrealengine.com/t/problem-with-subscribe/832398/5 "2023-03-29T17:05:02Z")

</div>

OMG thanks, take this ❤
