亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么下面的 python while 循環永遠不會中斷?它是一個簡單的機器人

為什么下面的 python while 循環永遠不會中斷?它是一個簡單的機器人

藍山帝景 2023-06-20 14:12:26
def turn():x=0while x==0:    #the players X co-ordinate, and the players Y co-ordinate is set to 513,437 respectively    player_x, player_y=513,437    #It looks for the HP bar of the monster, and then notes down the location in terms of left, right, height in the variable target (or target2, whichever it detects.)    target = pyautogui.locateOnScreen(os.path.expanduser(r'~\Desktop\wow bot\references\target.png'),                                      region=(0, 0, 1024, 768), confidence=.7)    target2 = pyautogui.locateOnScreen(os.path.expanduser(r'~\Desktop\wow bot\references\target2.png'),                                       region=(0, 0, 1024, 768), confidence=.7)    #this turns the target location into an X, and Y format. So the location of the mob gets turned into x and y position and stored in target_x and target_y    if target is not None or target2 is not None:        global targety        global targetx        target_point=pyautogui.center(target or target2)        targetx,targety=target_point    #distance a = square root of target_y minus players_y to the power of 2    distance_a=math.sqrt((targety-player_y)**2)    #distance h = square root of target_X minus player_x to the power of 2 plus target_y minus player_y to the power of 2    distance_h=math.sqrt((targetx-player_x)**2+(targety-player_y)**2)    #inverse tan of distance a divide by distance h    radian=math.acos(distance_a/distance_h)    #turns radian into degrees    theta=(radian*180/math.pi)    #displays output of the degrees    print((theta))    direction=player_x-targetx    print(direction)我不明白為什么上面的代碼沒有中斷?它是一個簡單的機器人,除了轉向它面對目標之外什么都不做。我希望循環中斷,以便之后我可以繼續執行另一項任務。
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

您的循環只會在theta=25您的第一個if條件聲明時中斷,theta>=25而嵌套的 if 條件聲明theta<=25then onlyx=1這是非常荒謬的,因此條件僅滿足theta=25



查看完整回答
反對 回復 2023-06-20
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號