Execute function every frame (Like in Unity)

Hi guys. I wanted to create a game that when someone reaches a certain value in the Z axis, something happens.

This is what i did:


using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces}

TestingDevice1 := class(creative_device):

    OnBegin<override>():void=

        ShowText()
                
    ShowText() : void =
        Playspace : fort_playspace = GetPlayspace()
        AllPlayers : []player = Playspace.GetPlayers()

        if(Player: player = AllPlayers[0]):
            if(FortniteCharacter : fort_character = Player.GetFortCharacter[]):
                Transform := FortniteCharacter.GetTransform()
                if(Transform.Translation.Z > 3500.0):
                    Print("Player is over Z: 3500.0")

So obvioulsy this runs only when the game is started, but it doesn’t happen every time someone goes at Z: 3500.0. Is there a function like “Update” from Unity to execute instructions every frame? Is there an alternative?

P.S. I’m very noob and english isn’t my first language so I’m sorry for any mistake

Hi,
you can replicate a function that executes every frame with a loop that calls Sleep(0.0).
When you pass 0.0 to Sleep, you suspend the coroutine execution until the next simulation frame.

    Tick()<suspends>:void=
        loop:
            # Your code here.
            Sleep(0.0)
    
    OnBegin<override>()<suspends>:void=
        spawn{Tick()}
4 Likes

Btw, it’s 30 fps (ticks per second). You won’t be able to make smooth movement there.

1 Like