# Function with no\_rollback effect can't be used after if statement

**URL:** <https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [August 14, 2023, 6:28pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954 "2023-08-14T18:28:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fisher007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fisher007](https://forums.unrealengine.com/u/Fisher007)\
**Post date:** [August 14, 2023, 6:28pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/1 "2023-08-14T18:28:45Z")

</div>

Hey,

I got stuck with an issue, was hoping someone might know the solution. I’m trying to apply a grind powerup to the activating player’s opposing team. I have a button, when the player activates it, I get his team and find the enemy team by comparing it using an if statement. Then I want to apply the grind powerup to all players on that team, but this gives the no\_rollback error due to the if statement.

```auto
ActivateSkating(Agent : agent): void=
                
        if:
            TeamCollection := GetPlayspace().GetTeamCollection()
            Teams := TeamCollection.GetTeams()
            MyTeam := TeamCollection.GetTeam[Agent]
            for (Team : Teams):
                if(Team <> MyTeam):
                    Players := TeamCollection.GetAgents[Team]
                    for(Player : Players):
                        SkatingPowerup.Pickup(Player)

```

---

<div class="post-metadata">

**Author:** ![MoSchmo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MoSchmo](https://forums.unrealengine.com/u/MoSchmo)\
**Post date:** [August 14, 2023, 7:56pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/2 "2023-08-14T19:56:44Z")

</div>

Hello. I did a little debugging on my end to try to figure out what your issue could be. When you get the “no\_rollback error” verse us trying to let you know that your code will unable to be restored to a previously defined state when a failed expression occurs.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/c/5ac3ccced383609f45b49a832e9e3336b68cc7b8.png)

I was able to find a slightly different way of writing your code, so that your function is able to recover from a failed expression, should it happen.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/8/c0869b1455cac710d9af03f19e4af95fa951ce9d.png)

I spelled Teams as **Teamss** on my end, because I have an existing class that I created called **Teams** so you can go ahead and change the spelling for that.

I hope this helps.

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [August 15, 2023, 1:11am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/3 "2023-08-15T01:11:21Z")

</div>

Following your lead, I refactored that code.

```auto
    ActivateSkating(Agent : agent): void=
        if:
            TeamCollection := GetPlayspace().GetTeamCollection()
            Teams := TeamCollection.GetTeams()
            MyTeam := TeamCollection.GetTeam[Agent]
        then:
            for:
                Team : Teams
                Team <> MyTeam
                Player : TeamCollection.GetAgents[Team]
            do:
                Print("Do something)

```

---

<div class="post-metadata">

**Author:** ![MoSchmo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MoSchmo](https://forums.unrealengine.com/u/MoSchmo)\
**Post date:** [August 15, 2023, 1:55am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/4 "2023-08-15T01:55:31Z")

</div>

This looks way cleaner as well. I will need to start using this format more often.

---

<div class="post-metadata">

**Author:** ![LoPing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loping/32/737300_2.png) [@LoPing](https://forums.unrealengine.com/u/LoPing)\
**Post date:** [August 15, 2023, 2:20am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/5 "2023-08-15T02:20:58Z")

</div>

Wow, I had no idea you could skip the parentheses and format like that. (Fifteen minutes after seeing your example, I saw that Epic used the same formatting in their ‘Stronghold’ map code.)

---

<div class="post-metadata">

**Author:** ![Fisher007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fisher007](https://forums.unrealengine.com/u/Fisher007)\
**Post date:** [August 15, 2023, 12:43pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/6 "2023-08-15T12:43:43Z")

</div>

You guys are amazing, thanks a lot to both of you! It works perfectly!

Edit: So I’m probably a dummy, but how do you end a "do: " section? I don’t seem to find any examples of this format (I checked the Stronghold map as well) and anything I put after this, it treats as if it were part of the for loop, no matter the indentation.

Btw, are there any good examples of using these TeamCollection functions? I have a hard time cracking what the data is behind them and how to properly interact with them by just looking at the Digest.

---

<div class="post-metadata">

**Author:** ![MoSchmo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MoSchmo](https://forums.unrealengine.com/u/MoSchmo)\
**Post date:** [August 15, 2023, 5:48pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/7 "2023-08-15T17:48:39Z")

</div>

> [@t.tutiya](#):
>
> ```auto
> ActivateSkating(Agent : agent): void=
> if:
> TeamCollection := GetPlayspace().GetTeamCollection()
> Teams := TeamCollection.GetTeams()
> MyTeam := TeamCollection.GetTeam[Agent]
> then:
> for:
> Team : Teams
> Team <> MyTeam
> Player : TeamCollection.GetAgents[Team]
> do:
> Print("Do something)
> #Write code here
> 
> ```

Have you tried writing any additional code you have on the same Indentation line as the **if:** and **then:**?

I haven’t used much of the TeamCollection functions in verse as of yet. There is a team\_settings\_and\_inventory\_device that let’s you create and configure a team. I’m not too sure on how well those two interact, but I would give them a try.

---

<div class="post-metadata">

**Author:** ![Fisher007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fisher007](https://forums.unrealengine.com/u/Fisher007)\
**Post date:** [August 16, 2023, 4:33pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/8 "2023-08-16T16:33:50Z")

</div>

No matter where I put, it gives an error. Except of course if I put to the very first line, but that means it’s outside of my class.

 ![2023-08-16 18_32_09-Game_Manager.verse - Test1 (Workspace) - Visual Studio Code](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/5/9853d77b143f48b7a35527da3c24a74d88a5cb4f.png)

---

<div class="post-metadata">

**Author:** ![MoSchmo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MoSchmo](https://forums.unrealengine.com/u/MoSchmo)\
**Post date:** [August 16, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/9 "2023-08-16T17:20:07Z")

</div>

Could you post a screenshot of what the error is saying? Also is there any other code below the block: in GiveExtraGold1() method? If so post that as well.

---

<div class="post-metadata">

**Author:** ![Fisher007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fisher007](https://forums.unrealengine.com/u/Fisher007)\
**Post date:** [August 17, 2023, 3:04pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/10 "2023-08-17T15:04:55Z")

</div>

There is nothing under it (just emply space and comments but I also deleted them to be sure). It say: Functions declared at this scope are not supported.(3502)

 ![2023-08-17 17_03_49-Game_Manager.verse - Test1 (Workspace) - Visual Studio Code](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/7/2/e72cde54242f232afa43a185754e7a828cc7d0e5.jpeg)

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [August 18, 2023, 2:14am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/11 "2023-08-18T02:14:57Z")

</div>

That is a different issue than `if:` or `do:`.  
A `block` expression is a concurrency expression. Therefore, the `<suspends>` effect specifier must be added to the function name.

---

<div class="post-metadata">

**Author:** ![Ep8Script](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ep8script/32/1170494_2.png) [@Ep8Script](https://forums.unrealengine.com/u/Ep8Script)\
**Post date:** [August 18, 2023, 10:12am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/12 "2023-08-18T10:12:31Z")

</div>

`block` isn’t a concurrency expression, it’s a synonym for braces

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [August 18, 2023, 11:01am UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/13 "2023-08-18T11:01:16Z")

</div>

@Ep8Script  
Sorry. You are right.

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

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/7/b77e99ccfd7cbc793054c8af78ef53dd6771608c.png)

See also.

> [@What is wrong with my function?](https://forums.unrealengine.com/t/what-is-wrong-with-my-function/1248221/13):
>
> using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Random } See [Create Your Own Device Using Verse](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\_de…

---

<div class="post-metadata">

**Author:** ![Fisher007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fisher007](https://forums.unrealengine.com/u/Fisher007)\
**Post date:** [August 18, 2023, 4:44pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/14 "2023-08-18T16:44:21Z")

</div>

Daaaamn! Well this was pretty lame from my side, my eyes are really not accustomed to noticing little rogue whitespaces. 🙂 Thanks for the help again (both of you)!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 17, 2023, 4:44pm UTC](https://forums.unrealengine.com/t/function-with-no-rollback-effect-cant-be-used-after-if-statement/1260954/15 "2023-09-17T16:44:48Z")

</div>

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