#Godot's `wrap()` function is useful for when you have a list of players (e.g. blue, green, red, etc.) and you want to change whose turn it is:

```
# Next player's turn.
current_player = wrap(current_player + 1, 0, PLAYERS.size())
```

https://docs.godotengine.org/en/stable/classes/[email protected]#class-globalscope-method-wrap

#Godot4 #GDScript #GameDev #Programming

@GlobalScope

Global scope constants and functions. Description: A list of global scope enumerated constants and built-in functions. This is all that resides in the globals, constants regarding error codes, keyc...

Godot Engine documentation
@ConditionalCoder I believe GDScript also has a modulo operator % so that, e.g., 42 % 10 == 2, which is useful in a lot of the common cases, but wrap seems potentially useful for cases where your lower bound isn't 0, where the arguments are potentially negative (which often causes unexpected behavior in %), etc
@puleo @ConditionalCoder There's also something to be said for readability. IMO wrap(...) tells me a lot more about the *goal* of the statement.