# Changing Data in an Infinite Loop

**URL:** <https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [May 27, 2024, 4:16pm UTC](https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601 "2024-05-27T16:16:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dr.Joske](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dr.joske/32/1014311_2.png) [@Dr.Joske](https://forums.unrealengine.com/u/Dr.Joske)\
**Post date:** [May 27, 2024, 4:16pm UTC](https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601/1 "2024-05-27T16:16:27Z")

</div>

Hi, what is better practice to use here,

```auto
#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.

---

<div class="post-metadata">

**Author:** ![TelesphorosGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/telesphorosgames/32/924355_2.png) [@TelesphorosGames](https://forums.unrealengine.com/u/TelesphorosGames)\
**Post date:** [May 28, 2024, 1:11am UTC](https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601/2 "2024-05-28T01:11:48Z")

</div>

#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

---

<div class="post-metadata">

**Author:** ![Dr.Joske](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dr.joske/32/1014311_2.png) [@Dr.Joske](https://forums.unrealengine.com/u/Dr.Joske)\
**Post date:** [May 28, 2024, 11:49am UTC](https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601/3 "2024-05-28T11:49:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TelesphorosGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/telesphorosgames/32/924355_2.png) [@TelesphorosGames](https://forums.unrealengine.com/u/TelesphorosGames)\
**Post date:** [May 28, 2024, 1:32pm UTC](https://forums.unrealengine.com/t/changing-data-in-an-infinite-loop/1875601/4 "2024-05-28T13:32:08Z")

</div>

Oh, sorry, didn’t understand the question 😅

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 🙂
