You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于限制taucher.xPosition最小值为0的循环逻辑问题求助

求助:限制taucher.xPosition最小值为0的循环逻辑问题

各位好,我现在碰到一个问题:当我持续按下左箭头键时,希望taucher.xPosition的数值不要低于0,到0就停下来不再减少。但目前实际运行时,按住左箭头键的输出是这样的:

10
x: 9
x: 8
x: 7
x: 6
x: 5
x: 4
x: 3
x: 2
x: 1
x: 0
x: -1
x: -2
x: -3

这是我当前使用的代码:

while True:
    inputLeft = False
    while inputLeft == False:
        if keyboard.is_pressed('right arrow'):
            taucher.moveright()
            print("x: ", taucher.xPosition)
            time.sleep(1)
            inputLeft = True

我之前试过用一个从500到0的for循环来限制,但没起到效果。想请教下大家,该怎么修改代码才能实现taucher.xPosition不低于0的需求呢?

备注:内容来源于stack exchange,提问作者Felix Wiens

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 09:19:28