help with objects and percent sign Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

help with objects and percent sign

16 Mar 2019, 02:21

hello

THIS works

Code: Select all

Var:={}
Var.first:="foo"
Var.second:="bar"
Var.third:="hi"
MsgBox, % Var.first
MsgBox, % Var.second
MsgBox, % Var.third
THIS

Code: Select all

Var:={}
Var.first:="foo"
Var.second:="bar"
Var.third:="hi"
MsgBox, %Var.first% %Var.second% %Var.third%
gives me the following compiling error:
The following variable name contains an illegal character: "Var.first"
How could i make the second option run correctly?
Thank you
just me
Posts: 9495
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: help with objects and percent sign  Topic is solved

16 Mar 2019, 02:49

Code: Select all

; MsgBox, %Var.first% %Var.second% %Var.third%
MsgBox, % Var.first . " " . Var.second . " " . Var.third
jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

Re: help with objects and percent sign

16 Mar 2019, 03:15

Hey, thank you very much! Your solution works!
Could i ask you to explain me where i was in error?
I make always so much confusion with this percent sign...
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 03:32

the name is "dot operator"
https://www.autohotkey.com/docs/Variables.htm#Operators

Actually, below is the more important info to use dot operator properly
https://www.autohotkey.com/docs/Language.htm#legacy-syntax
just me
Posts: 9495
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: help with objects and percent sign

16 Mar 2019, 04:40

When exactly are variable names enclosed in percent signs?might give you some hints.

In your case Var.first is not the name of a variable. first is just the name of a key stored in the object referenced by the variable Var. And because the dot is not allowed in the names of variables, AHK throws an error when you enclose it in percent signs to be used like the name of a variable.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 05:01

so,
I was wondering why some people try to use dot operator "always", most of the cases it could be omitted, of course this post too.
I, personally, like below than the above, in this case you do not have to worry about confusing usage of dot

Code: Select all

MsgBox, % Var.first . " " . Var.second . " " . Var.third  ;  Object access operator AND Concatenate operator
MsgBox, % Var.first " " Var.second " " Var.third          ;  Object access operator ONLY
just me
Posts: 9495
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: help with objects and percent sign

16 Mar 2019, 05:22

Since AHK has a concatenate operator (. / period / dot) I normally use it. Also, I usually put spaces around this operator. I don't like those AHK syntax elements which can be omitted. It's a source of confusion again and again without a real advantage. Because AHK needs to have 'auto-concat' in expressions 'thanks to this feature', it might surprise users with 'confusing' errors.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 05:43

yeah

some languages 'force' its users to use only ONE style, so it looks ugly
some languages 'free' its users to use ALL variant style, so it looks ugly

It was good to hear your standpoint clearly. Thanks for your time.

Regards
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 05:47

ah one more..

Though I have read the HELP document several times, I have failed to get the real meaning.
Have you ever met any situations that 'really' needed to use dot as a concatenate operator ?
In my case, negative, up until today.
Can I have a (or some) sample code ?

Regards
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: help with objects and percent sign

16 Mar 2019, 05:51

There are some really really rare situations in which not having a . operator will cause issues.
I don't remember here it happened to me, but it was extremly painful to figure out.
Recommends AHK Studio
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 05:56

yeah, that is why I have not met it yet
Thanks really really rare comment
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: help with objects and percent sign

16 Mar 2019, 05:58

Though I have read the HELP document several times, I have failed to get the real meaning.
Have you ever met any situations that 'really' needed to use dot as a concatenate operator ?
In my case, negative, up until today.
Can I have a (or some) sample code ?
. wrote: You may also omit the period to achieve the same result (except where ambiguous such as x -y, or when the item on the right side has a leading ++ or --).
So, eg,

Code: Select all

x := y := 0
msgbox % x . -y
You also need it when you want to continue the expression after a line break, eg,

Code: Select all

a := 1
. 1
Cheers.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 06:02

Ho..
I am happy to see the rare animals
Thanks, I will look into it more carefully
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 07:10

Donno...

This could be somewhat more deeper and wider meanings.
In that case I just quit.
Because, I do not have any kind of professional knowledge or experience about Computer Programming Language Design.

Below is not so proper comment for this brief question
So, I am not going to make any comment further in here.
Just leave this one as the last comment here.

Earlier I thought, AHK does not have any kind of type (data type)
But, I was wrong
It has 3 types clearly and 2 extras. So, AHK has 5 types.
- Strings, Numbers and Objects (Boolean, Nothing)

Then, if you execute an operation between Stings types, its result should be Strings type too.
Just like case3 and case4 below.
But, it executed as Numbers type operation, so the results are "wrong" <-- different result type and different result value.

Finally, I confirmed this problem in the case5 and case6.
I was supposed to have "12" (Numbers type) from case5 - but, it looks like "111" Strings type
I was supposed to have "-10" (Numbers type) from case6 - but, it looks like "1" Numbers type (or "1" Strings type)

I'd rather call it an operational 'BUG'

Code: Select all

x := 0
y := 0
a := "1"
b := "11"

MsgBox % ""
.  "case 1  " x - y "`n"
.  "case 2  " x . - y "`n"
.  "case 3  " a - b "`n"
.  "case 4  " a + b "`n"
.  "case 5  " "1" + "11" "`n"
.  "case 6  " "1" - "11" "`n"
jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

Re: help with objects and percent sign

16 Mar 2019, 07:18

damn, i am again in trouble with this thing...

now i would like to msgbox a long list of variables in the object with CRLF.
I tried this but it doesn't compile:

MsgBox,
(
% "First" . Var.first .
"`nSecond" . Var.second .
"`nSecond" . Var.third
)

May i get some additional help?
Thank you
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 07:22

Damn...

Code: Select all

MsgBox % ""
.  "First - " Var.first "`n"
.  "Second - " Var.second "`n" 
.  "Third - " Var.third
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 07:26

take a look at it too
https://www.autohotkey.com/docs/Scripts.htm#continuation

Alhasss.. it lacks the really useful usage of dot as a concatenation operator.
You have to go to dot operator part explanation again, then you see it at the last line.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: help with objects and percent sign

16 Mar 2019, 07:36

this is VERY difficult part for ALL beginners

because
They MUST understand the meaning of below, clearly !!
- expressions syntax
- command/legacy/traditional syntax

And
They MUST know/remember which Functions/Commands supports which syntax (or try_error it, all and every time, it really sucks).
garry
Posts: 3777
Joined: 22 Dec 2013, 12:50

Re: help with objects and percent sign

16 Mar 2019, 08:12

also example for msgbox

Code: Select all

Var:={}
Var.first:="foo"
Var.second:="bar"
Var.third:="hi"
;MsgBox, % Var.first . "`n" . Var.second . "`n" . Var.third
c:= Var.first . "`n" . Var.second . "`n" . Var.third
msgbox,%c%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Darkmaster006, haomingchen1998 and 172 guests