Question

First of all, sorry for making two questions in short interval, but I solved last one so I need help again. I'm coding bukkit plugins with jython/python... I'm pretty new to python/jython and I don't understand where I'm making mistake, take look at the code:

(everything is under class hween(PythonPlugin))                      
def CandyChance(self):
    chance = self.cfg.getString("main.candydropchance") #this works, I tried to print it and result is 10 (which I entered in config before)
    chancetotal = chance / 100

@hook.event("block.BlockBreakEvent", "HIGHEST")        
def onBlockBreakEvent(event):
    #something
    chancetotal = pyplugin.CandyChance() 
    if("Random.nextDouble() <= %s"%chancetotal):
       #do something

Thanks!

Was it helpful?

Solution

"It prints 10" doesn't tell you anything about what type it is. It's probably the string "10" and not the number 10 -- as you might guess from the method name getString. You can't divide a string by a number. Try doing:

chance = int(self.cfg.getString("main.candydropchance"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top