Reputation: 35682
this is my code :
vars_ = {
'attackUp':attackUp,'defenceUp':defenceUp,'magicUp':magicUp,'attType':attType,'weightDown':weightDown,
'accAttackSword':accAttackSword,'accAttackSaber':accAttackSaber,'accAttackAx':accAttackAx,
'accAttackHammer':accAttackHammer,'accAttackSpear':accAttackSpear,'accAttackFight':accAttackFight,
'accAttackBow':accAttackBow,'accAttackMagicGun':accAttackMagicGun,'accAttackMagic':accAttackMagic,
'mStrInstrument':mStrInstrument,'mStrCharms':mStrCharms,'accDefencePhy':accDefencePhy,
'accDefenceMag':accDefenceMag,'accWeight':accWeight,'bookTurn':bookTurn,'bookAttackPhy':bookAttackPhy,
'bookAttackMag':bookAttackMag,'bookStrInstrument':bookStrInstrument,'bookStrCharms':bookStrCharms,
'bookDefencePhy':bookDefencePhy,'bookDefenceMag':bookDefenceMag,'bookWeight':bookWeight,'name':name,
'plvl':plvl,'str':str,'ski':ski,'mag':mag,'spd':spd,'locX':locX,'locY':locY,'wName':wName,
'wAttack':wAttack,'wDefence':wDefence,'wWeight':wWeight,'wType':wType,'target':target,'title':title,
'uname':uname,'cUrl':cUrl,'mbCnt':mbCnt
}
oh my god , I spent a lot of time on this work , and maybe have more Variable to be added later ,
any easy way to do this ,
thanks
Upvotes: 0
Views: 1167
Reputation: 56684
I totally agree with @miku - look at how you are using the values and seriously refactor.
For example, a Character has Attributes (physical_attack, physical_defence, magic_attack, magic_defence, weight, speed) and Items; Weapons are Items, Swords and Axes and Spears and Bows are Weapons, a Saber is a Sword. Unarmed is a special default Weapon. Charms are Items, but apparently Books and StringedInstruments are Weapons?? Items have Attributes which are added to a Character's Attributes while equipped. Character also has level, location, target, and an accuracy rating for each weapon type (can a Weapon have an accuracy-modifier?).
If you break it down into a class hierarchy this way, it should be much easier to keep track of what you are doing.
Upvotes: 0
Reputation: 95
You could make an array of variable names and pull them out of the locals
dictionary.
x, y, z = 5, 10, 20
l = locals()
d = {}
for v in ['x', 'y', 'z']:
d[v] = l[v]
# d = {'y': 10, 'x': 5, 'z': 20}
locals
might work on it's own too if you're just wanting to look it up as a string.
attUp = locals()['attackUp']
Upvotes: 0
Reputation: 16778
I would stop and consider why you are doing this. I can't help but think its not necessary.
Even if you decide this is necessary (which i doubt) - You are pretty much recreating globals()
. Type that into your interpretter and see if you still want to do this.
Organize it further like senderle
suggested in your other post. And maybe post a broader question with help for organizing your project.
Upvotes: 3
Reputation: 994221
The first thing I would do is reformat that dictionary so there is one entry per line:
vars_ = {
'attackUp' : attackUp,
'defenceUp' : defenceUp,
'magicUp' : magicUp,
'attType' : attType,
'weightDown': weightDown,
# and so on
}
I have also lined up the columns so the whole list reads more easily.
Upvotes: 2