How do I use SuccessEvent on a timer device?

The title says it all, I want to use the data member “SuccessEvent” to execute a part of my code. I don’t exactly know how to do this because it uses “listenable” and I’m only familiar with “Subscribe” which isn’t the case here. Can anyone help?

TimerDevice.SuccessEvent.Subscribe(OnTimerFinish)

That’s it :slight_smile:

Getting this error:

1 Like

you have to define that method “OnTimerFinish” because that is what is going to get called when the timer finishes

What do you mean define, could you give an example?

You said you were familiar with “Subscribe” so I assumed you had written verse code before. Anyways, something like this:

OnTimerFinish(Agent:agent):void=
#whatever you want here

I meant that I read a few things about that, just never implemented it (I’m still learning verse so I’m not the best in the world). Anyways, I did that and it came up with an error:

It’s time for you to learn about Verse then :slight_smile: Here is one of my tutorials to get you up and running:

The quick answer though is that you have to tab in your line below the method

1 Like

I watched your tutorial and learned a few things :+1:. However, as for the code, it still gives me an error and I don’t think it’s linked to the actual indentation of the function. Everything else becomes underlined in red too. Can you help on this?

You’re missing indentation under your if statement

Tried a bunch of stuff and it just keeps messing up. Can you help, I’m really confused.

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 buttonActive2 : logic = false
        var buttonActive3 : logic = false
        var buttonActive4 : logic = false
        var buttonActive5 : logic = false
        var buttonActive6 : logic = false
        var buttonActive7 : logic = false
        var buttonActive8 : logic = false
        var buttonActive9 : logic = false
        var buttonActive10 : logic = false
        var buttonActive11 : logic = false
        var buttonActive12 : logic = false

        var activeOrders : int = 0

        #on timer success, get a random int
        OrderTimer.SuccessEvent.Subscribe(OnTimerFinish)

    OnTimerFinish(Agent:agent):void=
        var randomHouseGen:int = GetRandomInt(1,12)


        Print("{randomHouseGen}")
        #if activeOrders = 5, wait until it goes back to 3 to continue



        if(randomHouseGen = 1, activeOrders < 5, buttonActive1 = false):
            randomOrder(ButtonHouse1, "House 1")
            set buttonActive1 = true
            set activeOrders = activeOrders + 1


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

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

        ButtonHouseNum.Enable()

        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)

        Print("{pizza}" + " pizzas")

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

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

Sorry, the agent is a possible fail so it’s like this:

OnTimerFinish(Agent:?agent):void=

Add in that question mark

2 Likes

Yup, that was it. Thanks a lot

Thanks for your responses. This also worked in my project. If you dont mind could you explain what (Agent:?agent) does? I’ve never seen this without an equals. Usually I use (Agent := agent). I was appending the ? but keep having an error until I removed the equals sign. From my understanding ‘:=’ is used to assign a value to a variable that might fail. But what does ‘:’ by itself do? Thanks again!

I’m not sure about the := because someone told me about this. All I know is that you put the ? because Agent is failable and that’s always the case with timers no matter what

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