Function with no_rollback effect can't be used after if statement

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.

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)

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.

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.

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.

1 Like

Following your lead, I refactored that code.

    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)
2 Likes

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

1 Like

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.)

1 Like

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.

1 Like

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.

1 Like

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.

1 Like

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.

1 Like

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)

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.

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

1 Like

@Ep8Script
Sorry. You are right.

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

See also.

1 Like

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

1 Like

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