Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Dict w/Array Values Passed as Params?
    primarykey
    data
    text
    <p>Alright so I have a dict with keys that point to an array of 5 values. These 5 values I pass to a class to sort out and feed me info etc. </p> <h2>Main</h2> <p>So, this works, but my querstion is is there a better way of exytracting the array to pass to the 'weapon' class, or do i just need to <code>'wepstats[0],wepstats[1]'</code> etc? Or is there a better way of going about this? I'm all ears as Im only learning to do this stuff.</p> <pre><code>class Main(): def weaponDamage(self): #print 15 * 2.22 wdb = WeaponDB() wepstats = wdb.getWeaponStats('Sword') wep = Weapon(wepstats[0],wepstats[1],wepstats[2],wepstats[3],wepstats[4]) wep2 = Weapon("Sword", 5, 55, 1.55, 2.1) print wep print wep2 s = sayThings() greet = s.Say() self.crit = wep.getDamageCrtRND() self.scrit = wep.getDamageSCrtRND() self.avg = wep.getDamageAvg() self.high = wep.getDamageHigh() self.low = wep.getDamageLow() self.mod = wep.getDamageMod() self.norm = wep.getDamageNrmRND() self.name = wep.getWeaponName() print greet print "-----------" print "Name: " + self.name print "-----------" print "High: %s" % self.high print "Low : %s" % self.low print "Avg : %s" % self.avg print "Crit: %s" % self.crit print "--------------------" </code></pre> <h2>Dict</h2> <p><strong>EDIT:</strong> Should I be making a DB of items in this manner in the first place? Is there a more logic method of doing this? </p> <pre><code>class WeaponDB(): """Here be thine weapons of thy holy might""" def __init__(self): self.script = { 'None': "Error: No Weapon stats to get selected.", 'Sword': ("Sword", 5, 55, 1.55, 2.1), } def getWeaponStats(self, key = 'None'): try: return self.script[key] except KeyError: return self.script['None'] </code></pre> <h2>Class useing the values as parameters</h2> <pre><code>class Weapon(): def __init__(self, name = "Stick", high = 1, low = 0, critMod = 1, scritMod = 2): self.rng = randNum() self.name = name self.high = high self.low = low self.critMod = critMod self.scritMod = scritMod def getWeaponName(self): return self.name def getDamageHigh(self): return self.high def getDamageLow(self): return self.low def getDamageMod(self): return self.critMod def getDamageSMod(self): return self.scritMod etc... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload