【发布时间】:2020-10-21 08:23:58
【问题描述】:
我有一个浮动列表 listItemPos 和另一个浮动列表,每个帧都在更新 playPosition。
每次playPosition 超过listItemPos 中的一个值时,我都会尝试执行一段代码。
这就是我的代码的样子:
listItemPos.sort() #sort the item positions
# This is the loop being called each frame:
for x in range(0, len(listItemPos)):
if playPosition >= listItemPos[x]:
print("I passed item number " + str(x))
"""
This is where I would like to have a function execute only once
when reaching one of the value of my list.
"""
到目前为止,正如预期的那样,每次传递我的列表值时,每帧的打印量都会增加。
【问题讨论】:
-
你能编辑你的问题并把示例输入和预期输出放在那里吗?
标签: python python-3.x list loops