Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

When single percent % signs are used in the script?


  • Please log in to reply
3 replies to this topic
manoj aggarwal
  • Members
  • 72 posts
  • Last active: Nov 13 2015 10:03 AM
  • Joined: 12 Oct 2014

Friends i wish to know that when we use single % signs in the scripts. I know when we use double % signs in the script, but i do not know in what scenario we use single % sign. As in the following script the single percent sign is used-

~Right::
MouseGetPos, outx, outy
adjx := outx + 4 
MouseMove, % adjx, % outy
return

Can anybody explain why single percent signs are used in the above script. thanks.



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

A single % forces expression mode for that parameter.

MouseMove, % adjx, % outy

is the same as:

MouseMove, %adjx%, %outy%

and since mousemove parameters allow expression syntax you can do this:

MouseMove, adjx, outy

MouseMove

X, Y

The x/y coordinates to move the mouse to, which can be expressions.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Basically, the lone percent sign changes how a parameter is processed. Consider this example with MsgBox:

car:="truck"
blue:="red"
own:="sold"
I:="You"
a:="the"
MsgBox,,1, I own a blue car
MsgBox,,2, "I own a blue car"
MsgBox,,3, % I own a blue car
MsgBox,,4, % I " " own " " a " " blue " " car ; this includes literal strings of spaces
MsgBox,,5, % "I own a blue car"
return

Notice in the last message box that the quotation marks make it like the first message box, by passing literal strings in the parameter. That's how most parameters are accepted. The biggest difference is in functions which expect variables to be passed instead of literal strings - so you'll sometimes see quotes around a parameter, such as in GetKeyState() which has a second parameter often passed as "P" to indicate a physical press. (Sending P with no quotes will evaluate the variable P which is likely undefined, and so that second parameter is treated as if it's blank.)

 

(Edit: Named the MsgBoxes so you can tell which is which so you can get a better understanding of the script and how the different syntaxes produce different results.)



lilygel
  • Members
  • 249 posts
  • Last active: May 26 2017 04:13 AM
  • Joined: 18 Feb 2015
lol
I used single-percent there because I'm too lazy to use two. Also, note the space after the percent sign.

A single % forces expression mode for that parameter.

and since mousemove parameters allow expression syntax you can do this:
[code=auto:0]
MouseMove, adjx, outy


I didn't know that. I always forces expression mode or use the usual %variable% style. :p