Changing Data in an Infinite Loop

Hi, what is better practice to use here,

#1 version
PlayerTracking(FortCharacter:fort_character)<suspends>:void=

    loop:

        PlayerPosition : vector3 = FortCharacter.GetTransform().Translation
        PlayerX : float = PlayerPosition.X
        PlayerY : float = PlayerPosition.Y
        PlayerZ : float = PlayerPosition.Z

        Sleep(0.0)

#2 version
PlayerTracking(FortCharacter:fort_character)<suspends>:void=

    var PlayerPosition : vector3 = vector3{}
    var PlayerX : float = 0.0
    var PlayerY : float = 0.0
    var PlayerZ : float = 0.0

        loop:

            set PlayerPosition = FortCharacter.GetTransform().Translation
            set PlayerX = PlayerPosition.X
            set PlayerY = PlayerPosition.Y
            set PlayerZ = PlayerPosition.Z

            Sleep(0.0)

#1 Redeclaring constants every iteration or #2 declaring variables before the loop and changing their values every iteration.

#1 doesn’t actually do anything with or store the data, the loop sets the scope of the variables declared within it each cycle, so I would go with #2

So there is more code in that function where I use and compare that data.
I was just wondering, since it’s an infinite loop, if one way is more efficient than the other.

Oh, sorry, didn’t understand the question :sweat_smile:

One thing you can do if you’re worried about efficiency or overhead is just put like a 0.2 sleep in the loop so that it doesn’t happen every single frame if not necessary :slight_smile: