首先,很抱歉在短时间内提出了两个问题,但我解决了最后一个问题,所以我再次需要帮助。我正在使用 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
谢谢!
最佳答案
“It prints 10”并没有告诉你任何关于它是什么类型的信息。它可能是字符串 "10"
而不是数字 10
—— 正如您可能从方法名称 getString
中猜到的那样。您不能将字符串除以数字。尝试这样做:
chance = int(self.cfg.getString("main.candydropchance"))
关于python -/: 'unicode' and 'int' 不支持的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19575650/