I am new to programming and I am teaching myself Python and as a hobby I am making a text-based RPG.
My question is this; I want to store a list of weapons, armours etc that can be easily edited without screwing up my whole program. My thinking is that I make a separate module for them equipment.py and store them in a list like;
equipment = [
#Longsword
w1 = 15
#Axe
w2 = 17
]
I would just import this and use the values assigned to them would be used in whatever combat engine I decide to create. Is this even correct? Terrible coding conventions? I have much to learn and any wisdom you have to share is much appreciated.
EDIT: From the excellent answer below I have started it code it, how does my code look?
equipment = {
'Longsword': { 'cost': 50,
'damage': 19,
'element': 'physical',
'description': 'Long steel blade used by the knights of Coamrin. The weight allows it to cleave foes with relative ease.'}
'Estoc': { 'cost': 45,
'damage': 17,
'element': 'physical',
'description': 'Expertly crafted thin, steel blade designed for thrust and swiping motions.'}
}
Any tips? I have read through PEP 8 but my knowledge is not good enough or there is nothing specific enough to help in this particular case
I would suggest that using a python dictionary (rather than a list) would be preferable.
That way you can refer to the longswords value as
equipment['Longsword']rather than by its position in the listequipment[0].Putting it in a separate module could be a good idea, perhaps inside a module containing the attack/defence functionality, and other items effects.
.
One other suggestion you might be interested in (depending on the RPG’s functionality) would be to have another dictionary for this and other attributes, so you could add other attributes in the future. That is,
This allows additional functionality to be added later (without breaking previous mechanics).