所以自从我触及任何类型的脚本以来已经有4年了,我想为了编写脚本而重新使用它。我喜欢随之而来的问题解决方案。 Annnyyyyway。
我正在制作一个小机器人来测试我可以在第一次尝试中走多远。现在我知道代码非常糟糕而且很长,我知道我可能会让它变得更短更有效(因此欢迎任何和所有提示)。
所以我的问题是,在这个速度方面我做错了什么?因为在部分:
;Select first company. Any missions?
LabelMission1:
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
sleep 223
它的速度很慢,因为它需要整整3秒才能在检查可用任务和转到下一个公司之间切换。按下'和空间'我尝试通过将睡眠时间从平均600降低到平均200来加快代码速度,但这似乎没有做多少,它加速了一些部分但不是公司之间的转换和检查任务。
所以任何帮助都是受欢迎的,如果你想完全分解我的代码并写出超高效的代码,我对此很好,只要向我解释你做了什么。我想尽可能多地向你们学习:)
编辑:这是用Scite4Autohotkey编写的C ++
格尔茨,
杜桑
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SetKeyDelay, 20, 20
SetMouseDelay, 200
#MaxThreads 255
;What gamemode is the game in? Solo or private?
;send {Escape}
; ImageSearch FoundX, FoundY, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Mode_Solo_Play.bmp
; {
; If ErrorLevel = 0
; return
; {
; If ErrorLevel = 1
;
--------------------------------------------------------------------------------------------------------------------------
;Is the game loaded and in bulletin board? ((If not can we see starport service?)) -> ((If not can we see mission board?))
labelstart: ;this label is the startingpoint of the script
sleep 4500
ImageSearch pointX, pointY, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Starport_services.bmp ;Can we see starport services?
{
sleep 150
If ErrorLevel = 1 ; If it CAN'T find Starport Services, it will look for Mission Board instead.
{
sleep 150
ImageSearch pointX2, pointY2, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Mission_Board.bmp ;Can we see Mission Board?
if ErrorLevel = 1 ;If it CAN'T find mission board, it will ask for it.
{
MsgBox, 48, Something went wrong!, I can't find "Mission Board" or "Starport Services" anywhere.
MsgBox, 4132, Something went wrong!, Do you wish to retry?
IfMsgBox Yes
{
MsgBox, 4160, Restarting, Click OK and switch back to game with "Starport Services" Open!! `n(YOU GET 15 SECONDS TIME)
sleep 15000
gosub labelstart
}
else IfMsgBox no
ExitApp
}
If ErrorLevel = 0 ;If it finds Mission Board it will navigate to the Mission Board.
{
Sleep 143
SendEvent s
Sleep 177
SendEvent {Space}
sleep 10000
gosub LabelMissionBoard
}
}
If ErrorLevel = 0 ;If it finds Starport services it will navigate to the Mission Board.
{
Sleep 200
SendEvent {space}
sleep 15234
SendEvent s
sleep 134
SendEvent {Space}
sleep 10000
gosub LabelMissionBoard
}
}
;Are we in the mission board?
LabelMissionBoard: ;Jump here to check for missionboard
ImageSearch pointX3, pointY3, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Mission_Board_Open.bmp ; Is the mission board open?
{
sleep 233
if ErrorLevel = 1 ;If it CAN'T find the Mission Board Open.
{
MsgBox, 16, Something went wrong!, I can't find the "Mission Board" Opened`, did I open it? `n- If I didn't`, please open it and press OK. (10 seconds before I retry.) `n- If I did please restart the script (end it with ctrl+R)
sleep 9989
gosub LabelMissionBoard
}
if ErrorLevel = 0 ;If it CAN find the Mission Board open.
{
sleep 50
gosub LabelEnoughCredits
}
}
;Do we have enough credits? (over 1,000,000) ((Probably pixel search here))
LabelEnoughCredits:
;LINE IS TEMPORARLEY DISABLED
;PixelSearch, Px, Py, 246, 190, 246, 190, 0xD1CECD, 10, Fast ;Looking for credits over 1,000,000 ((Credits shift to the left when below 1kk, so it should no longer be there.))!!UNTESTED!!
;LINE IS TEMPORARLEY DISABLED
ImageSearch pointX3, pointY3, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Above_1_Million.bmp ;Looking for credits over 1,000,000 ((Credits shift to the left when below 1kk, so it should no longer be there.))!!UNTESTED!!
Sleep 80
{
Sleep 91
If ErrorLevel = 1 ;If it finds out you DON'T have above 1,000,000.
{
MsgBox, 0, MONEY PROBLEM!, Unfortunately you seem to have ran out of funds. If I go further you won't be able to pay your insurance!`n- Please Make sure you have above 1`,000`,000.
sleep 98
ExitApp
}
If Errorlevel = 0 ;If it find out you DO have above 1,000,000.
{
sleep 100
gosub LabelAID
}
}
;Is the filter "Aid" selected?
LabelAID:
ImageSearch pointX4, pointY4, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Aid_Selected.bmp ;Can we find Aid?
{
sleep 123
If Errorlevel = 1 ;If it ISN'T selected.
{
sleep 170
send a
sleep 163
send a
sleep 133
send a
sleep 125
send a
sleep 160
send a
sleep 163
send a
sleep 148
send a
sleep 151
send a
sleep 140
Send w
Sleep 142
Send w
Sleep 136
Send w
Sleep 132
Send w
Sleep 147
Send w
Sleep 146
Send w
Sleep 154
Send w
Sleep 137
Send w
Sleep 124
Send {Space} ;Selecting filter
Sleep 1107
send s
Sleep 113
send s
Sleep 118
send s
Sleep 118
send s
Sleep 116
send s
Sleep 139
Send {Space} ;AID filter is selected.
Sleep 123
send s
sleep 143
send s
sleep 154
send {Space} ;First mission is selected.
Sleep 162
Gosub labelMission1
}
If Errorlevel = 0 ;If aid IS selected.
{
Sleep 143
send s
sleep 143
send s
sleep 154
send {Space}
Sleep 162
Gosub labelMission1 ;If found select first Group to check for mission
}
}
;Select first company. Any missions?
LabelMission1:
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
sleep 223
if Errorlevel = 1 ; If mission ISN'T found.
{
Sleep 150
Send s
sleep 160
send {Space}
Sleep 113
gosub LabelMission2
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected1:
Sleep 266
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 50
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected1 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 700
send {Space}
Sleep 700
send {Space}
sleep 831
send {backspace}
sleep 322
Send {backspace}
sleep 241
send {backspace}
sleep 951
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Select 2nd company. Any missions?
LabelMission2:
ImageSearch pointX6, pointY6, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
sleep 143
if Errorlevel = 1 ; If mission ISN'T found.
{
Sleep 550
Send s
sleep 660
send {Space}
Sleep 613
gosub LabelMission3
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected2:
Sleep 266
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 50
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected2 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 700
send {Space}
Sleep 700
send {Space}
sleep 1231
send {backspace}
sleep 322
Send {backspace}
sleep 241
send {backspace}
sleep 3251
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Select 3rd company. Any missions?
LabelMission3:
ImageSearch pointX7, pointY7, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
Sleep 163
if Errorlevel = 1 ; If mission ISN'T found.
{
Sleep 450
Send s
sleep 460
send {Space}
Sleep 513
gosub LabelMission4
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected3:
Sleep 66
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 250
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected3 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 700
send {Space}
Sleep 700
send {Space}
sleep 1231
send {backspace}
sleep 322
Send {backspace}
sleep 241
send {backspace}
sleep 3251
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Select 4th company. Any missions?
LabelMission4:
ImageSearch pointX8, pointY8, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
Sleep 196
if Errorlevel = 1 ; If mission ISN'T found.
{
Sleep 150
Send s
sleep 260
send {Space}
Sleep 113
gosub LabelMission5
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected4:
Sleep 66
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 250
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected4 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 700
send {Space}
Sleep 700
send {Space}
sleep 1231
send {backspace}
sleep 322
Send {backspace}
sleep 241
send {backspace}
sleep 3251
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Select 5th company. Any missions?
LabelMission5:
ImageSearch pointX9, pointY9, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
Sleep 131
if Errorlevel = 1 ; If mission ISN'T found.
{
Sleep 350
Send s
sleep 360
send {Space}
Sleep 313
gosub LabelMission6
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected5:
Sleep 66
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 250
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected5 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 700
send {Space}
Sleep 700
send {Space}
sleep 1231
send {backspace}
sleep 322
Send {backspace}
sleep 241
send {backspace}
sleep 3251
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Select 6th company. Any missions?
LabelMission6:
ImageSearch pointX11, pointY11, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k.bmp
{
sleep 385
if Errorlevel = 1 ; If mission ISN'T found.
{
sleep 273
gosub LabelSoloPrivate ;If at this point it CAN'T find anymore missions to turn in, it will go to gamemode check.
}
if Errorlevel = 0 ; If missions IS Found.
{
sleep 143
Send D
Sleep 160
Send w
Sleep 166
Send w
Sleep 129
Send w
Sleep 177
Send w
Sleep 167
Send w
Sleep 146
Send w
Sleep 172
Send w
Sleep 112 ;Top of mission list selected
Label25kSelected6:
Sleep 66
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Donate25k_selected.bmp ;Did it select the 25k Mission?
{
sleep 250
If Errorlevel = 1 ;If Mission ISN'T selected.
{
sleep 376
send s
sleep 185
gosub Label25kSelected6 ;If it CAN'T find the mission by pressing 'S' once, it will retry untill it does.
}
If ErrorLevel = 0 ;If Mission IS selected.
{
send w
sleep 50
send w
sleep 50
send w
sleep 50
send {Space}
sleep 360
Send D
Sleep 260
send {Space}
Sleep 300
send {Space}
Sleep 300
send {Space}
sleep 231
send {backspace}
sleep 822
Send {backspace}
sleep 841
send {backspace}
sleep 851
gosub Labelstart ;Mission is turned in, going back to start to see the refresh if there is anymore.
}
}
}
}
;Back to Main Menu, Were we in Solo or Private?
LabelSoloPrivate:
sleep 678
send {Escape}
sleep 700
ImageSearch pointX5, pointY5, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Mode_Solo_Play.bmp ;Is the game mode set on Solo play?
{
Sleep 284
If ErrorLevel = 1 ;If game mode ISN'T solo play
{
sleep 786
gosub LabelModeIsPrivate
MsgBox, 0, Current Gamemode, Gamemode is private!
sleep 6000
}
If ErrorLevel = 0 ;If game mode IS Solo Play
{
Sleep 600
gosub LabelModeIsSolo
MsgBox, 0, Current Gamemode, Gamemode is solo!
Sleep 6000
}
}
;If solo, select private. -- If Private, select solo.
LabelModeIsSolo:
{
Sleep 256
send w
Sleep 612
send w
sleep 302
send {space}
sleep 630
send d
sleep 234
send {space}
sleep 15000 ;Waiting for Main Menu to load.
send s
sleep 953
send {space} ;Selecting start.
Sleep 943
send s
Sleep 823
send {space} ;Selecting Private group.
Sleep 723
send {space} ;Starting Private group.
Sleep 18213 ;Waiting for game to start.
gosub labelstart
}
LabelModeIsPrivate:
{
Sleep 502
send w
Sleep 682
send w
sleep 511
send {space}
sleep 687
send d
sleep 799
send {space}
sleep 17631 ;Waiting for Main Menu to load.
send s
sleep 653
send {space} ;Selecting start.
Sleep 943
send s
Sleep 723
send s
Sleep 623
send {space} ;Selecting solo.
Sleep 16347 ;Waiting for game to start.
gosub labelstart
}
;Eat, sleep, rave. Repeat.
^r::ExitApp ;Kills the script, if it goes haywire.
答案 0 :(得分:0)
没关系,我完全搞砸了,我现在明白为什么。谢谢你的帮助......
编辑:非常好。
整个剧本就像我在原帖中说的那样简直太可怕了。至于它有什么问题,不是在这里的任何人的帮助下,即使我知道有人看到它并看到错误并决定不帮助。
IF语句和Searchimage设置在错误的{}内。因为在整个脚本的构建中没有任何意义,它甚至可以开始的奇迹。
这对初学者来说应该是什么样子。
ImageSearch pointX, pointY, 0, 0, 1920, 1080, *125 C:\Users\ICECOLD\Desktop\new_test\Starport_services.bmp ;Can we see starport services?
{
sleep 150
If ErrorLevel = 1 ; If it CAN'T find Starport Services, it will look for Mission Board instead.
{
sleep 150
ImageSearch pointX2, pointY2, 0, 0, 1920, 1080, *100 C:\Users\ICECOLD\Desktop\new_test\Mission_Board.bmp ;Can we see Mission Board?
if ErrorLevel = 1 ;If it CAN'T find mission board, it will ask for it.
{
MsgBox, 48, Something went wrong!, I can't find "Mission Board" or "Starport Services" anywhere.
MsgBox, 4132, Something went wrong!, Do you wish to retry?
IfMsgBox Yes
{
MsgBox, 4160, Restarting, Click OK and switch back to game with "Starport Services" Open!! `n(YOU GET 15 SECONDS TIME)
sleep 15000
gosub labelstart
ExitApp
If ErrorLevel = 0 ;If it finds Mission Board it will navigate to the Mission Board.
{
Sleep 143
SendEvent s
Sleep 177
SendEvent {Space}
sleep 10000
gosub LabelMissionBoard
If ErrorLevel = 0 ;If it finds Starport services it will navigate to the Mission Board.
{
Sleep 200
SendEvent {space}
sleep 15234
SendEvent s
sleep 134
SendEvent {Space}
sleep 10000
} gosub LabelMissionBoard
}
}
}
}
}
正如您在上面的代码中看到的那样,而不是我最初发布的代码的开头。其中有多个事情同时发生,所以不是在找到一个图像之后停下来而是一直不停,但它没有按下按钮只计算“睡眠”。无论出于何种原因,我都没有f& ^ *(线索,因为我此时基本上都是初学者。尽管如此,还是一个咸的。所以有你的答案,现在请原谅我再也不会回到这里了。