在我看来,我缺少了一些关于线程计时器如何工作的关键知识。到目前为止,我一直在试图找到一些代码来帮助我理解定时器和其他的args和kwargs,但我一直很不走运
我正试图通过创建一些类似于魔兽世界铸造机制的代码来学习。正如你所看到的,这是非常原始的,但我现在多次碰到这个错误。有人能详细说明我对线程计时器的理解有什么问题吗?这样我以后就可以毫不犹豫地使用它了? 先谢谢你
from threading import Timer
def scope(x):
if x<0:
print("Has to be between 1 and 0")
elif x>1:
print("Has to be between 1 and 0")
else:
return x
def damage(spp,res):
scope(res)
c = spp - spp*res
return c
def fire_projectile():
print("Projectile fired!")
def casting_time(n_time,haste):
#Every haste unit deducts the casting time by 0.001 seconds.
general_time = n_time - haste/1000.00
print(general_time)
c = Timer(general_time, lambda: fire_projectile())
c.start()
return c
#The timer is here to count down the time needed in order for projectile to get launched.#
spells = {'Fireball': (250, 2), 'Pyrobalst' : (400, 3), 'Flamestrike': (190, 1.5)}
#First value is the natural damage of the spell. Second value is the casting time w/o haste.
classes = {'Death Knight': (0.6, 500), 'Mage': (0.2, 1200), "Priest": (0.4, 800)}
#First value is resistance to fire damage. Second value is haste.
print(damage(spells['Fireball'][0],classes['Death Knight'][0]))
print(casting_time(spells['Fireball'][1], classes['Mage'][1]))
在我写了最后两行之后,第一行似乎运行得很好,但是第二行有一些问题
代替: 100 0.8 炮弹发射
进程已完成,退出代码为0
我得到: 100 0.8 计时器(线程1,从11268开始) 炮弹发射
进程已完成,退出代码为0
目前没有回答
相关问题 更多 >
编程相关推荐