What does this mean?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quadra123

I’m following this tutorial however i cant understand this one:
Why does he add “% composite_sprites.hair_spritesheets.size()” after “(curr_hair+1)” ?
(around 7:58)

:bust_in_silhouette: Reply From: Gluon

the % is the modulo function, it finds the remainder of something so he is checking if the remainder of curr_hair+1 / the size of the spritesheet has a remainder. What he is doing here is making certain that if he has three different hairsyles then the integer can never go above 3. The below may make it a bit clearer but would be less efficient code

if curr_hair + 1 > composite_sprites.hair_spritesheet.size():
    curr_hair = 1
else
    curr_hair = curr_hair + 1

The above code would do the same thing as his code but would be a little bit less efficient.