What is wrong with my function?

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:

randomOrder(HouseButton) : void =
     #stuff goes here

Or

randomOrder(HouseButton) : void = {
     #stuff goes here
}
1 Like

I tried that and it just underlines everything in red

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= {}

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

Functions cannot be defined within functions.

@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!

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 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 for a good basis to follow.

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

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.

What do you mean another method?

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.

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

See Create Your Own Device Using 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

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

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):

        #...
1 Like

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:

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")

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

randomOrder(ButtonHouse1, "House 1")
randomOrder(ButtonHouseNum:conditional_button_device, HouseName:string):void =

Looks like that solved it, thanks a bunch

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