# A function that create button\_device and set up

**URL:** <https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [June 10, 2023, 11:02am UTC](https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802 "2023-06-10T11:02:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [June 10, 2023, 11:02am UTC](https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802/1 "2023-06-10T11:02:50Z")

</div>

I want to create a function that creates a button\_device, sets up a handler function, and returns that object.

However, the following function gives me a compile error.

```auto
CreateLoudButton(Name:string, Handler: widget_message->void):button_loud = 
    Button:button_loud = button_loud:
        DefaultText := StringToMessage(Name)
    Button.OnClick().Subscribe(Handler)
    return Button

```

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/4/8/948d1caff5fffa49deb0c40d35d1eb6094026261.png)

What am I doing wrong?  
Thank you.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [June 10, 2023, 2:27pm UTC](https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802/2 "2023-06-10T14:27:35Z")

</div>

This should work :

```auto
my_custom_handler := class:
    Callback: type{_(:widget_message) : void}

    HandleOnClickEvent(Payload:widget_message):void=
        Callback(Payload)

your_ui_class := class():

    CreateLoudButton(Name:string, Handler: widget_message->void):button_loud = 
        Button:button_loud = button_loud:
            DefaultText := StringToMessage(Name)

        CustomHandler := my_custom_handler{Callback := Handler}
        Button.OnClick().Subscribe(CustomHandler.HandleOnClickEvent)

        return Button

```

I use this kind of setup literally in all my files, don’t know if it’s the right way to go, but it should work!

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [June 11, 2023, 12:32am UTC](https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802/3 "2023-06-11T00:32:26Z")

</div>

Your code worked perfectly!! Thank you!!!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 11, 2023, 12:33am UTC](https://forums.unrealengine.com/t/a-function-that-create-button-device-and-set-up/1194802/4 "2023-07-11T00:33:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
