Modifying external variables while selecting them based on a local variable

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

I’m building a skill system and currently facing the following challenge:
I have skill1, skill2, skill3. The different skill levels are stored in a global script PlayerStats as values of the variables skill1_level, skill2_level, skill3_level.
When a point is assigned to a skill in my GUI script, I would like to update the level in the PlayerStats based on which skill got points assigned. Since the selected skill is already stored in a skill variable within my GUI script I would like to avoid going through all the if/elif/else nonsense to set the new level.
I have used something similar in the script to get the current level of the skill:

PlayerStats.get(skill + "_level")

But I’ve been unable to figure out how to set (or rather, +1) that value.

:bust_in_silhouette: Reply From: exuin
PlayerStats.set(skill + "_level", PlayerStats.get(skill + "_level") + 1)

Thanks, this will come in very handy.

fraggynator | 2021-05-16 18:52