首先,很抱歉在短时间内提出了两个问题,但我解决了最后一个问题,因此我再次需要帮助。我正在用jython / python编码bukkit插件...我对python / jython还是很陌生,我不明白自己在哪里犯错,请看下面的代码:

(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


谢谢!

最佳答案

“它打印10”不会告诉您任何类型的信息。可能是字符串"10",而不是数字10,您可能会从方法名称getString中猜到。您不能将字符串除以数字。尝试做:

chance = int(self.cfg.getString("main.candydropchance"))

关于python -/不支持的操作数类型:“unicode”和“int”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19575650/

10-12 17:38
查看更多