Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Marevixo |
Hi, recently I realized that instead of using boolean variable, we can just use groups, example:
Let’s say we have player and enemy. If player has sword, enemy runs away. If not, enemy attacks player. In the player script, we can declare:
var has_sword : bool = true
Then enemy checks that:
if player.has_sword:
escape()
else:
attack()
But instead, we can just add the player to group “has_sword”, and then enemy checks:
if player.is_in_group("has_sword"):
escape()
else:
attack()
I’m just wondering, if one of this options is more efficient than the other (consumes less RAM). Also, imagine we have 15 global variables in code, and every of them can be replaced with group, so maybe we can have smaller code (we don’t declare groups on top). What do you think?