Page 1 of 1

Help with a few subjects

Posted: 09 Aug 2016, 18:04
by Noam527
just as the title says...:
1) what do these mean and do?:
.=
:=
!=
(If there are more, include them in the answer please)
When should these be used?

2) Let's say I want the script to pause itself until my A_cursor is on IBeam.
So I thought about this thing:

<start of the script here>

Loop
{
If A_cursor = IBeam
{Break}
}

<end of the script here>

So two questions about what I typed up here:
I) How do I type the bolded line correctly? (so it will actually check if the cursor is on IBeam "mode")
II) Is there any way to shorten/optimize that script?

3) Is there any command (or anything I can make) that tells the script-reading to return to a certain line?
So I can type something like:

if <expression>
ReturnTo 13 ; return to line 13.


Any help is great!

Re: Help with a few subjects

Posted: 09 Aug 2016, 19:43
by J Richards
1)
.= - I have no idea, maybe someone can fill us in.
:= - Dunno what it's called, an expression operator? Basically it expects an expression on the right.

var = cheese ; var contains a string, "cheese"
var := "cheese" ; var contains a string, "cheese"
var := cheese ; var is assigned the contents of cheese. If cheese were a variable with a number, say 5, then var would contain a "5"

!= - not equals

if (cheese != 5)
msgbox cheese isn't five!

2)
Loop
{
If (A_cursor = "IBeam")
Break
sleep 50 ; script waits 0.05 seconds before continuing
}

That work? Untested.

3)
Lables, unless you're inside a function.

DoThis:
var += 1
if (var < 10)
Goto DoThis
NowDoThis:
var2 += 10
if (var2 < 100)
Goto NowDoThis
MsgBox var is at least ten (%var%) and var2 is at least one hundred (%var2%).
return


Hope I got that right.

Re: Help with a few subjects

Posted: 09 Aug 2016, 20:35
by Noam527
J Richards wrote:1)
.= - I have no idea, maybe someone can fill us in.
:= - Dunno what it's called, an expression operator? Basically it expects an expression on the right.

var = cheese ; var contains a string, "cheese"
var := "cheese" ; var contains a string, "cheese"
var := cheese ; var is assigned the contents of cheese. If cheese were a variable with a number, say 5, then var would contain a "5"

!= - not equals

if (cheese != 5)
msgbox cheese isn't five!

2)
Loop
{
If (A_cursor = "IBeam")
Break
sleep 50 ; script waits 0.05 seconds before continuing
}

That work? Untested.

3)
Lables, unless you're inside a function.

DoThis:
var += 1
if (var < 10)
Goto DoThis
NowDoThis:
var2 += 10
if (var2 < 100)
Goto NowDoThis
MsgBox var is at least ten (%var%) and var2 is at least one hundred (%var2%).
return


Hope I got that right.
Thanks, you've solved a lot of my questions! but few are unsolved...
Oh by the way, you typed: "var +=1"
Does it mean that var is at least 1?

Re: Help with a few subjects

Posted: 09 Aug 2016, 20:52
by J Richards
var += 1 increments by one, the same thing as var++ and var := var + 1

Except, var := var + 1 doesn't seem to work if var is empty. So you'd have to make sure it wasn't empty beforehand. var = 0

Re: Help with a few subjects

Posted: 09 Aug 2016, 21:16
by TAC109
For information on .= etc., read up on this subject in the help file. Scroll down to 'assign' in the table, although the whole page is worth a read.

Re: Help with a few subjects

Posted: 09 Aug 2016, 21:18
by hunter99
Hi, look here:

https://autohotkey.com/docs/Variables.htm#Operators


All your questions are answered there.
hunter99

Re: Help with a few subjects

Posted: 10 Aug 2016, 13:22
by Shadowpheonix
For question 1, see the link provided by TAC109 and Hunter99.

For question 2, there are several possible methods. Here are two of them...

Code: Select all

; Method 1
Loop {    ; This curly brace...
	If A_cursor = IBeam
		Break    ; The Break command does not get wrapped in curly braces.
}    ; ... and this one are optional, since the "If A_cursor = IBeam" line is the only line being processed in the loop.


; Method 2
While A_Cursor != "IBeam"
	Continue
For question 3, Labels combined with GoTo are the closest option. GoSub can also be quite useful. :)