# What is wrong with my function?

**URL:** <https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [August 2, 2023, 12:25pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221 "2023-08-02T12:25:34Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 2, 2023, 12:25pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/1 "2023-08-02T12:25:34Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/9/9f9a9fe153f5be0703126d927ea4644ffbb6e442.png)

---

<div class="post-metadata">

**Author:** ![AxelCapek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/axelcapek/32/950074_2.png) [@AxelCapek](https://forums.unrealengine.com/u/AxelCapek)\
**Post date:** [August 2, 2023, 1:53pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/2 "2023-08-02T13:53:48Z")

</div>

Exactly what is says! Your function block never ends!

In order to close the function you must use `}` at the end of the function block.

However, this is only preference. You can omit `{` `}` and instead just use indenting as formatting.

Examples:

```auto
randomOrder(HouseButton) : void =
     #stuff goes here

```

Or

```auto
randomOrder(HouseButton) : void = {
     #stuff goes here
}

```

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 2, 2023, 5:50pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/3 "2023-08-02T17:50:40Z")

</div>

I tried that and it just underlines everything in red

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/f/7df51980e67c070de59d961dc26384a730178abc.png)

---

<div class="post-metadata">

**Author:** ![AxelCapek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/axelcapek/32/950074_2.png) [@AxelCapek](https://forums.unrealengine.com/u/AxelCapek)\
**Post date:** [August 2, 2023, 11:08pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/4 "2023-08-02T23:08:33Z")

</div>

Your code is indented incorrectly under `OnBegin`. To fix, select the enterity of your randomOrder code block and use `Shift + Tab` to outdent.

The next issue you’ll face is OnBegin will have no code, to fix that simply add code or change to `OnBegin<overrides>()<suspends>void= {}`

---

<div class="post-metadata">

**Author:** ![ChefGoldblumPG](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chefgoldblumpg/32/742169_2.png) [@ChefGoldblumPG](https://forums.unrealengine.com/u/ChefGoldblumPG)\
**Post date:** [August 3, 2023, 3:21am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/5 "2023-08-03T03:21:57Z")

</div>

Hey nelmi - i think it has to do with the elseif, i think verse has it so it needs to be `else if(bla bla bla):`

Seen on this page [If](https://dev.epicgames.com/documentation/en-us/uefn/if-in-verse)

---

<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:** [August 3, 2023, 3:36am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/6 "2023-08-03T03:36:37Z")

</div>

Functions cannot be defined within functions.

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 3, 2023, 10:28am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/7 "2023-08-03T10:28:00Z")

</div>

@ChefGoldblumPG  
@AxelCapek

Tried what you both said but comes up with this error on the SetItemCountRequired()

I think @t.tutiya might be right about functions not being able to be defined inside other functions. That kinda sucks if that’s true but if you know anything else I can try, please say!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/a/e5adde2504b2fa2b4e79319fb212e5cc2f9a277b.png)

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 3, 2023, 10:51am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/8 "2023-08-03T10:51:24Z")

</div>

Hey, It’s true, you cannot define a function within a function until they add something like an anonymous function in the future. There are a few more things wrong with your function it would seem:

- There seems to be no reason you need that function to be defined within the other function unless I’m missing some context of what you’re trying to do.

- You can make [switch statements](https://dev.epicgames.com/documentation/en-us/uefn/case-in-verse) in verse to use instead of `if` `else` etc.

- House button is a string but you are trying to call the `SetItemCountRequired` method on it. An extension function could technically make that work but it would likely only return a new value which you aren’t doing anything with.

- Naming style and indentation isn’t consistent. In verse brackets are optional and without them indentation matters. see the [UEFN style guide here](https://dev.epicgames.com/documentation/en-us/uefn/verse-code-style-guide-in-unreal-editor-for-fortnite) for a good basis to follow.

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 3, 2023, 5:37pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/9 "2023-08-03T17:37:35Z")

</div>

Hey, thanks for the reply. Basically, I’m trying to apply that code to 12 switches picked randomly, which is why originally I was going with this function but since that doesn’t work, I’ll just copy and paste for each. Unless you know any other way to make this neater (a working function alternative you could say), please let me know

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 3, 2023, 5:51pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/10 "2023-08-03T17:51:38Z")

</div>

From the info I have in your snippet there’s nothing preventing you making that another method on your device. So instead of putting `randomOrder` inside the OnBegin method scope, add it below as another method.

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 3, 2023, 6:24pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/11 "2023-08-03T18:24:14Z")

</div>

What do you mean another method?

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 3, 2023, 7:48pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/12 "2023-08-03T19:48:07Z")

</div>

I think there may be a misunderstanding. If you post your latest complete code snippet (as text) I may be able to suggest some improvements. You shouldn’t need to copy paste the code.

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 3, 2023, 10:05pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/13 "2023-08-03T22:05:58Z")

</div>

> using { /Fortnite.com/Devices }  
> using { /Verse.org/Simulation }  
> using { /UnrealEngine.com/Temporary/Diagnostics }  
> using { /Verse.org/Random }
> 
> # See [Create Your Own Device Using Verse](https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse) for how to create a verse device.
> 
> # A Verse-authored creative device that can be placed in a level
> 
> testing := class(creative\_device):
> 
> ```
> @editable
> OrderTimer : timer_device = timer_device{}
> 
> @editable
> ButtonHouse1 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse2 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse3 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse4 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse5 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse6 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse7 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse8 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse9 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse10 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse11 : conditional_button_device = conditional_button_device{}
> @editable
> ButtonHouse12 : conditional_button_device = conditional_button_device{}
> 
> # Runs when the device is started in a running game
> OnBegin<override>()<suspends>:void=
> # TODO: Replace this with your code
> 
>     
> var pizza1 : int = GetRandomInt(0,3)
> var slurp1 : int = GetRandomInt(0,3)
> var icecream1 : int = GetRandomInt(0,3)
> 
> if (pizza1 = 0):
> ButtonHouse1.SetItemCountRequired(0,0)
> else if (pizza1 = 1):
> ButtonHouse1.SetItemCountRequired(0,1)
> else if (pizza1 = 2):
> ButtonHouse1.SetItemCountRequired(0,2)
> else if (pizza1 = 3):
> ButtonHouse1.SetItemCountRequired(0,3)
> 
>         
> 
> if (slurp1 = 0):
> ButtonHouse1.SetItemCountRequired(1,0)
> else if (slurp1 = 1):
> ButtonHouse1.SetItemCountRequired(1,1)
> else if (slurp1 = 2):
> ButtonHouse1.SetItemCountRequired(1,2)
> else if (slurp1 = 3):
> ButtonHouse1.SetItemCountRequired(1,3)
> 
> if (icecream1 = 0):
> ButtonHouse1.SetItemCountRequired(2,0)
> else if (icecream1 = 1):
> ButtonHouse1.SetItemCountRequired(2,1)
> else if (icecream1 = 2):
> ButtonHouse1.SetItemCountRequired(2,2)
> else if (icecream1 = 3):
> ButtonHouse1.SetItemCountRequired(2,3)
> 
> Print ("Order from House 1:")
> if (pizza1 > 0):
> Print("{pizza1}" + " pizzas")
> 
> if (slurp1 > 0):
> Print("{slurp1}" + " milkshakes")
> 
> if (icecream1 > 0):
> Print("{icecream1}" + " ice creams")
> 
> ```
> 
> > Blockquote

This is the code block for the first house, basically what I was gonna copy and paste

---

<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:** [August 4, 2023, 1:58am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/14 "2023-08-04T01:58:17Z")

</div>

In verse, indentation by whitespace is a very important rule for defining any scope.

```auto
testing := class(creative_device):

    #"OnBegin" is a function.
    OnBegin<override>()<suspends>:void =
        #OnBegin()`s scope (so you can't define other function in the scope)
        randomOrder(ButtonHouse1)

    randomOrder(HouseButton:string):void =
        #randomOrder()`s scope
        var pizza1 : int = GetRandomInt(0,3)
        var slurp1 : int = GetRandomInt(0,3)
        var icecream1 : int = GetRandomInt(0,3)

        if (pizza1 = 0):

        #...

```

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 4, 2023, 10:06am UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/16 "2023-08-04T10:06:46Z")

</div>

So I updated my code after your suggestions and it worked, but when I call the function and fill in the multiple parameters, it comes up with errors:

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
testing := class(creative_device):

    @editable
    OrderTimer : timer_device = timer_device{}

    @editable
    ButtonHouse1 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse2 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse3 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse4 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse5 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse6 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse7 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse8 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse9 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse10 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse11 : conditional_button_device = conditional_button_device{}
    @editable
    ButtonHouse12 : conditional_button_device = conditional_button_device{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        # TODO: Replace this with your code
        
        var buttonActive1 : logic = false
        var ActiveOrders : int = 0
        randomOrder("ButtonHouse1", "House 1")
        set buttonActive1 = true
        set ActiveOrders = ActiveOrders + 1

    
    randomOrder(ButtonHouseNum:string, HouseName:string):void =

        var pizza : int = GetRandomInt(0,3)
        var slurp : int = GetRandomInt(0,3)
        var icecream : int = GetRandomInt(0,3)

        if (pizza = 0):
            ButtonHouseNum.SetItemCountRequired(0,0)
        else if (pizza = 1):
            ButtonHouseNum.SetItemCountRequired(0,1)
        else if (pizza = 2):
            ButtonHouseNum.SetItemCountRequired(0,2)
        else if (pizza = 3):
            ButtonHouseNum.SetItemCountRequired(0,3)

            

        if (slurp = 0):
            ButtonHouseNum.SetItemCountRequired(1,0)
        else if (slurp = 1):
            ButtonHouseNum.SetItemCountRequired(1,1)
        else if (slurp = 2):
            ButtonHouseNum.SetItemCountRequired(1,2)
        else if (slurp = 3):
            ButtonHouseNum.SetItemCountRequired(1,3)

        if (icecream = 0):
            ButtonHouseNum.SetItemCountRequired(2,0)
        else if (icecream = 1):
            ButtonHouseNum.SetItemCountRequired(2,1)
        else if (icecream = 2):
            ButtonHouseNum.SetItemCountRequired(2,2)
        else if (icecream = 3):
            ButtonHouseNum.SetItemCountRequired(2,3)

        Print ("Order from " + HouseName)
        if (pizza > 0):
            Print("{pizza}" + " pizzas")

        if (slurp > 0):
            Print("{slurp}" + " milkshakes")

        if (icecream > 0):
            Print("{icecream}" + " ice creams")

```

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 4, 2023, 1:27pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/17 "2023-08-04T13:27:53Z")

</div>

Looks like you need to make the `ButtonHouseNum` parameter of type `conditional_button_device` and remove the string on your property name:

```auto
randomOrder(ButtonHouse1, "House 1")

```

```auto
randomOrder(ButtonHouseNum:conditional_button_device, HouseName:string):void =

```

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 4, 2023, 5:04pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/18 "2023-08-04T17:04:54Z")

</div>

Looks like that solved it, thanks a bunch

---

<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:** [September 3, 2023, 5:05pm UTC](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/19 "2023-09-03T17:05:42Z")

</div>

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