HelpAutoIT syntax

Posts 115 of 28 · Page 1 of 2
AutoIT syntax
I'm really confused about how the syntax in AutoIT works sometimes.

Sometimes you have have spaces between different parts of functions or variable settings. All of the following are currently working fine with spaces.
Code:
MouseClick("left", $XColumn1, $YRow1, 1)
$Paused = NOT $Paused
$PixelCheck = PixelGetColor($PixelCheckBoatX,$PixelCheckBoatY)
And yet, when I was just trying to implement an AP spending delay, the following refused to work until I took out the spaces.

Code:
ElseIf $APTimes > 0 Then
$APTimes = $APTimes - 1
And made it look like

Code:
ElseIf $APTimes>0 Then
$APTimes=$APTimes-1
Any idea where the line of differentiation is between where to have spaces are where not to?
Quote Originally Posted by Zaiakunokami View Post
I'm really confused about how the syntax in AutoIT works sometimes.

Sometimes you have have spaces between different parts of functions or variable settings. All of the following are currently working fine with spaces.
Code:
MouseClick("left", $XColumn1, $YRow1, 1)
$Paused = NOT $Paused
$PixelCheck = PixelGetColor($PixelCheckBoatX,$PixelCheckBoatY)
And yet, when I was just trying to implement an AP spending delay, the following refused to work until I took out the spaces.

Code:
ElseIf $APTimes > 0 Then
$APTimes = $APTimes - 1
And made it look like

Code:
ElseIf $APTimes>0 Then
$APTimes=$APTimes-1
Any idea where the line of differentiation is between where to have spaces are where not to?
There is no reason it should not work with spaces.

But I would do it like:

$APTimes =- 1
Quote Originally Posted by DanK View Post
There is no reason it should not work with spaces.

But I would do it like:

$APTimes =- 1
Is there any true difference between the two methods, aside from yours has fewer keystrokes?
Quote Originally Posted by Zaiakunokami View Post
Is there any true difference between the two methods, aside from yours has fewer keystrokes?
It's just the proper way to do it.
I don't understand either, I put the same extract of code on a small context to try it and it's working as it should:
Code:
$APTimes = 10
If False Then
ElseIf $APTimes > 0 Then
  $APTimes = $APTimes - 1
EndIf
msgbox(48, "Alert", $APTimes) ;=> 9
Could it be you made other changes at the same time?

Anyway, I wanted to ask you something Zaiakunokami, how are you developing certain parts of your bots? I'm creating some helpers functions to make my life easier when creating new bots or modifying them, for example here is a lazy working bot for trampled plains:
Code:
#include "botlib.au3"

Func Bot()
  $runs = get_runs(10)
  For $i = 1 To $runs
    hit_start()
    skip_map(3)
    sleep(1000*75) 
    god()
    ohk()
    walk("w",8000)
    While NOT battle_cleared_screen_present()
      paladin1()
      tentacle(3)
    WEnd
    hit_replay()
  Next
EndFunc
BUT! Since I just started I'm laking several helpers like error detecting or spending AP which I see you're developing now, so I'm wondering if you are going to release them to see if I can get more ideas on how to work around it or improve what I already have

For example for battle_cleared_screen_present() I compare a fixed number of pixels that belong to the "badge" that's shown on the battle screen, is that how you do it or you have another way to tell when the battle has been cleared?

Thank you.
Quote Originally Posted by japmsn View Post
I don't understand either, I put the same extract of code on a small context to try it and it's working as it should:
Code:
$APTimes = 10
If False Then
ElseIf $APTimes > 0 Then
  $APTimes = $APTimes - 1
EndIf
msgbox(48, "Alert", $APTimes) ;=> 9
Could it be you made other changes at the same time?

Anyway, I wanted to ask you something Zaiakunokami, how are you developing certain parts of your bots? I'm creating some helpers functions to make my life easier when creating new bots or modifying them, for example here is a lazy working bot for trampled plains:
Code:
#include "botlib.au3"

Func Bot()
  $runs = get_runs(10)
  For $i = 1 To $runs
    hit_start()
    skip_map(3)
    sleep(1000*75) 
    god()
    ohk()
    walk("w",8000)
    While NOT battle_cleared_screen_present()
      paladin1()
      tentacle(3)
    WEnd
    hit_replay()
  Next
EndFunc
BUT! Since I just started I'm laking several helpers like error detecting or spending AP which I see you're developing now, so I'm wondering if you are going to release them to see if I can get more ideas on how to work around it or improve what I already have

For example for battle_cleared_screen_present() I compare a fixed number of pixels that belong to the "badge" that's shown on the battle screen, is that how you do it or you have another way to tell when the battle has been cleared?

Thank you.
Honestly, your code as it is currently, is more advanced than most of mine. Mine is over-complicated and a jumbled mess.

I'm not an advanced coder, hell, I can't even make a For/Next command work properly. But what I can do is put hours of time into refining the If/ElseIf/Else and While and Do/Until commands that I do understand.

I have the battle cleared screen check for the buttons, as they are 0 black and not easy to replicate in all three spots in any dungeon. Plus, it doubly serves as an error checker, as if two of the buttons are there, but the third is not (which is a common connection time out from host error screen), it knows to move on the the error clearing procedure.

I'm not really a person to go to for coding tips and tricks, as my code isn't pretty. Just functional.
Quote Originally Posted by Zaiakunokami View Post
Honestly, your code as it is currently, is more advanced than most of mine. Mine is over-complicated and a jumbled mess.

I'm not an advanced coder, hell, I can't even make a For/Next command work properly. But what I can do is put hours of time into refining the If/ElseIf/Else and While and Do/Until commands that I do understand.

I have the battle cleared screen check for the buttons, as they are 0 black and not easy to replicate in all three spots in any dungeon. Plus, it doubly serves as an error checker, as if two of the buttons are there, but the third is not (which is a common connection time out from host error screen), it knows to move on the the error clearing procedure.

I'm not really a person to go to for coding tips and tricks, as my code isn't pretty. Just functional.
Paste this into a new script.. Study it and then run the script, it should help you understand how they work.

Code:
msgbox("", "ExampleTitle", "We are about to enter the for loop")
for $example = 1 to 10
 msgbox("", "ExampleTitle", $example)
Next
msgbox("", "ExampleTitle", "Done")
Quote Originally Posted by Zaiakunokami View Post
.
.
.
I have the battle cleared screen check for the buttons, as they are 0 black and not easy to replicate in all three spots in any dungeon. Plus, it doubly serves as an error checker, as if two of the buttons are there, but the third is not (which is a common connection time out from host error screen), it knows to move on the the error clearing procedure.

I'm not really a person to go to for coding tips and tricks, as my code isn't pretty. Just functional.
Now that's good info for me, I don't usually bot for more than an hour so I don't see errors to often.

Well, I really don't care if the code is messy or whatever, it's just to get some ideas not replicate it as it is. Anyway, if you finish this I guess that just by the instructions you'll give I'll have an idea of your approach.

Thank you.

btw, I'm not an "advanced coder" either, DanK is one IMO, saw his AutoVin, really neat idea.
Quote Originally Posted by DanK View Post
Paste this into a new script.. Study it and then run the script, it should help you understand how they work.

Code:
msgbox("", "ExampleTitle", "We are about to enter the for loop")
for $example = 1 to 10
 msgbox("", "ExampleTitle", $example)
Next
msgbox("", "ExampleTitle", "Done")
So, for my error checking process, rather than my current:

Code:
If $ErrorCountdown = 0 Then
		Call("Forfeit")
Else 
ToolTip("SinBotv2.2 is now taking steps to remove errors. Waiting for all error messages to appear", 50, 50)
		Sleep(500)
		Send("{ALT DOWN}")
		MouseClick("left", $CloseBattleScreenX, $CloseBattleScreenY, 1)
		Sleep(500)
		Send("{ALT UP}")
		Sleep(500)
		Do
			$GameUIErrorPixel = PixelGetColor($GameUIErrorPixelX,$GameUIErrorPixelY)
		Until $GameUIErrorPixel = 0 Or $GameUIErrorPixel = 12957332
		If $GameUIErrorPixel = 0 Then
			Sleep(1000)
			Send("{ALT DOWN}")
			Sleep(100)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(1000)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(100)
			Send("{ALT UP}")
			$ErrorCountdown = $ErrorCountdown - 1
			Call("LeaveAndRunColhen")
		ElseIf $GameUIErrorPixel = 12957332 Then
			$ErrorCountdown = $ErrorCountdown - 1
			Call("SelectMap")
		EndIf
EndIf
It should look more like:

Code:
For $ErrorCountdown = 1 to 5
ToolTip("SinBotv2.2 is now taking steps to remove errors. Waiting for all error messages to appear", 50, 50)
		Sleep(500)
		Send("{ALT DOWN}")
		MouseClick("left", $CloseBattleScreenX, $CloseBattleScreenY, 1)
		Sleep(500)
		Send("{ALT UP}")
		Sleep(500)
		Do
			$GameUIErrorPixel = PixelGetColor($GameUIErrorPixelX,$GameUIErrorPixelY)
		Until $GameUIErrorPixel = 0 Or $GameUIErrorPixel = 12957332
		If $GameUIErrorPixel = 0 Then
			Sleep(1000)
			Send("{ALT DOWN}")
			Sleep(100)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(1000)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(100)
			Send("{ALT UP}")
			Call("LeaveAndRunColhen")
		ElseIf $GameUIErrorPixel = 12957332 Then
			Call("SelectMap")
		EndIf
Next
	Call("Forfeit")
Do I have this right?
Quote Originally Posted by Zaiakunokami View Post
So, for my error checking process, rather than my current:

Code:
If $ErrorCountdown = 0 Then
		Call("Forfeit")
Else 
ToolTip("SinBotv2.2 is now taking steps to remove errors. Waiting for all error messages to appear", 50, 50)
		Sleep(500)
		Send("{ALT DOWN}")
		MouseClick("left", $CloseBattleScreenX, $CloseBattleScreenY, 1)
		Sleep(500)
		Send("{ALT UP}")
		Sleep(500)
		Do
			$GameUIErrorPixel = PixelGetColor($GameUIErrorPixelX,$GameUIErrorPixelY)
		Until $GameUIErrorPixel = 0 Or $GameUIErrorPixel = 12957332
		If $GameUIErrorPixel = 0 Then
			Sleep(1000)
			Send("{ALT DOWN}")
			Sleep(100)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(1000)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(100)
			Send("{ALT UP}")
			$ErrorCountdown = $ErrorCountdown - 1
			Call("LeaveAndRunColhen")
		ElseIf $GameUIErrorPixel = 12957332 Then
			$ErrorCountdown = $ErrorCountdown - 1
			Call("SelectMap")
		EndIf
EndIf
It should look more like:

Code:
For $ErrorCountdown = 1 to 5
ToolTip("SinBotv2.2 is now taking steps to remove errors. Waiting for all error messages to appear", 50, 50)
		Sleep(500)
		Send("{ALT DOWN}")
		MouseClick("left", $CloseBattleScreenX, $CloseBattleScreenY, 1)
		Sleep(500)
		Send("{ALT UP}")
		Sleep(500)
		Do
			$GameUIErrorPixel = PixelGetColor($GameUIErrorPixelX,$GameUIErrorPixelY)
		Until $GameUIErrorPixel = 0 Or $GameUIErrorPixel = 12957332
		If $GameUIErrorPixel = 0 Then
			Sleep(1000)
			Send("{ALT DOWN}")
			Sleep(100)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(1000)
			MouseClick("left",$GameUIErrorPixelX,$GameUIErrorPixelY,1)
			Sleep(100)
			Send("{ALT UP}")
			Call("LeaveAndRunColhen")
		ElseIf $GameUIErrorPixel = 12957332 Then
			Call("SelectMap")
		EndIf
Next
	Call("Forfeit")
Do I have this right?
Well it would run that block of code 5 times, not sure why you want to do all that 5 times though..
Quote Originally Posted by DanK View Post
Well it would run that block of code 5 times, not sure why you want to do all that 5 times though..
Yeah, five times is my intent. If the bot errors out in attempting to get to the boat 5 times in a row, it assumes that the character is in the wrong spot or is having issues with selecting the boat properly.

In this case it moves on to the function that I have to pull up the cc_shiplist_ui command, and manually select the boat through there and try to attempt to launch it.

One thing that I thought of after writing that block of code, would I need to have an "$ErrorCountdown = 1" somewhere else after a successful boat launch as to reset the counter at that point, or will it run it 5 times (or until successful) every time that it encounters that command?
Quote Originally Posted by Zaiakunokami View Post
Yeah, five times is my intent. If the bot errors out in attempting to get to the boat 5 times in a row, it assumes that the character is in the wrong spot or is having issues with selecting the boat properly.

In this case it moves on to the function that I have to pull up the cc_shiplist_ui command, and manually select the boat through there and try to attempt to launch it.

One thing that I thought of after writing that block of code, would I need to have an "$ErrorCountdown = 1" somewhere else after a successful boat launch as to reset the counter at that point, or will it run it 5 times (or until successful) every time that it encounters that command?
Every time the code gets to For $ErrorCountDown = 1 to 5

$Errorcountdown is assumed to start at 1 and end at 5. So no you don't need to declare that ahead of time, it's being declared in the For line.
Quote Originally Posted by DanK View Post
Every time the code gets to For $ErrorCountDown = 1 to 5

$Errorcountdown is assumed to start at 1 and end at 5. So no you don't need to declare that ahead of time, it's being declared in the For line.
That's about what I assumed.

One more question on the For usage.
Is it possible to have a For command countdown a variable and do three different conditions instead of two? My newly implemented "Smart AP Spender" has a triple condition style of If/ElseIf/Else/EndIf, where each part is the same variable, but at differing numbers.
Quote Originally Posted by Zaiakunokami View Post
That's about what I assumed.

One more question on the For usage.
Is it possible to have a For command countdown a variable and do three different conditions instead of two? My newly implemented "Smart AP Spender" has a triple condition style of If/ElseIf/Else/EndIf, where each part is the same variable, but at differing numbers.
You would have to show me an example of what you have for me to understand the question.
Quote Originally Posted by DanK View Post
You would have to show me an example of what you have for me to understand the question.
Code:
Func Skill()
	If $AP=1 	Then
		If $APTimes>2 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after " & $APTimes & " more runs.", 50, 50)
		ElseIf $APTimes=2 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after " & $APTimes-1 & " more run.", 50, 50)
		ElseIf $APTimes=1 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after the current run.", 50, 50)
		EndIf
		Sleep($SkillDelay)
		If $APTimes=0 OR $APTimes<0 Then
			If $SmartAP=0 Then
				ToolTip("SinBotv2.2 cannot be stopped during AP spending process. Please wait until finished.", 50, 60)
				Send("v")
				Send("{ALT DOWN}")
				MouseClick("left", $SkillBoxX, $SkillBoxY, 1) ; Selects All
				Call("SkillSelect")
				MouseClick("left", $XTab2, $SkillBoxY, 1) ; Combat
				Call("SkillSelect")
				MouseClick("left", $XTab3, $SkillBoxY, 1) ; Training
				Call("SkillSelect6")
				MouseClick("left", $XTab4, $SkillBoxY, 1) ; Restoration
				Call("SkillSelect8")
				MouseClick("left", $XTab5, $SkillBoxY, 1) ; Equipment
				Call("SkillSelect8")
				MouseClick("left", $XTab6, $SkillBoxY, 1) ; SP
				Call("SkillSelect6")
				Send("{ALT UP}")
			ElseIf $SmartAP=1 Then
				Send("v")
				Send("{ALT DOWN}")
				MouseClick("left", $SkillBoxX, $SkillBoxY, 1) ; Selects All
				Call("SkillSelect")
			EndIf
			Sleep(500)
			If FileExists ( $IniFile ) Then
				$APTimes=IniRead ( $IniFile, "skill", "APTimes", 40)
			Else
				$APTimes=40
			EndIf
			Sleep($LaunchButtonDelay)
			Call("Launch")
		ElseIf $APTimes>0 Then
			$APTimes=$APTimes-1
			Sleep($LaunchButtonDelay)
			Call("Launch")
		EndIf
	ElseIf $AP=0	Then
		Sleep($LaunchButtonDelay)
		Call ("Launch")
	Else
		MsgBox(0, "SinBotv2.2", "INI File Error. AP value must be 0 or 1.")
		Call("ExitBot")
	EndIf
EndFunc
Is there any way to better optimize this code using For/Next or any other commands?
Posts 115 of 28 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?