Nov-23-2019, 03:27 PM
For checking if one thing is equal to one of two other things, you can use or:
if myPlayer.job == 'warrior' or myPlayer.job == 'mighty warrior':However, it is generally simpler to use the 'in' operator:
if myPlayer.job in ('warrior', 'mighty warrior'):Now, you can also use a dictionary:
HP_BY_JOB = {'warrior': 100, 'mighty warrior': 100, 'wizard': 50, 'mighty wizard': 50} player_hp = HP_BY_JOB[my_player.job]You could have a similar one for MP. That makes the code a lot simpler when you have a lot of jobs. Another thing you could do is have each job store all of it's base stats:
JOB_STATS = {'warrior': {'hp': 100, 'mp': 20}, 'wizard': {'hp': 50, 'mp': 120}, ...} my_player.stats = JOB_STATS[my_player.job].copy()That makes them easier to assign to the player, but it does make them a little harder to get from the player, because
my_player.hp
is now my_player.stats['hp']
. You could use setattr to get around this:JOB_STATS = {'warrior': {'hp': 100, 'mp': 20}, 'wizard': {'hp': 50, 'mp': 120}, ...} for stat, value in JOB_STATS[my_player.job].items(): setattr(my_player, stat, value)Now it's just
my_player.hp
again. Just be careful with setattr that there isn't a key in the dictionary that is going to overwrite some important attribute of my_player.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures