testing 'or' as a variable name

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

testing 'or' as a variable name

30 Nov 2019, 13:00

Based on this post:
« What's on your mind? » - Page 213 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=17&t=52&p=303516#p303516

There are places here and there where AHK v1 could be improved re. error handling.
(Note: although considerations have to be made re. 'breaking changes'.)

Code: Select all

;AHK v1
;q:: ;test 'or' as a parameter
;note: 'or' is not allowed as a variable name in AHK v2
ol := "a"
ot := "b"
or := "c"
orr := "c"
ob := "d"
varname := "or"
MsgBox, % MyFunc(ol, ot, or, ob)
MsgBox, % MyFunc(ol, ot, %varname%, ob)
MsgBox, % MyFunc(ol, ot, 1 or 2, ob)
MsgBox, % MyFunc(ol, ot, orr, ob)
return

MyFunc(oParams*)
{
	local
	vOutput := ""
	for vKey, vValue in oParams
		vOutput .= vKey " " vValue "`r`n"
	return vOutput
}

Code: Select all

;AHK v2
;note: 'or' is not allowed as a variable name in AHK v2
ol := "a"
ot := "b"
;or := "c"
orr := "c"
ob := "d"
varname := "or"
%varname% := "c"
;MsgBox(MyFunc(ol, ot, or, ob))
MsgBox(MyFunc(ol, ot, %varname%, ob))
MsgBox(MyFunc(ol, ot, 1 or 2, ob))
MsgBox(MyFunc(ol, ot, orr, ob))

MyFunc(oParams*)
{
	local
	vOutput := ""
	for vKey, vValue in oParams
		vOutput .= vKey " " vValue "`r`n"
	return vOutput
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: testing 'or' as a variable name

30 Nov 2019, 22:36

btw its the same for varname "and" also, and probably others

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: testing 'or' as a variable name

30 Nov 2019, 22:44

Reserved words for AHK v2 are listed here:
Concepts and Conventions | AutoHotkey v2
https://lexikos.github.io/v2/docs/Concepts.htm#names

Although not here, the AHK v1 situation is somewhat different:
Concepts and Conventions | AutoHotkey
https://www.autohotkey.com/docs/Concepts.htm#names

I feel for you with that very surprising, (no messages so) tough to debug error.
A good a-ha moment when you realised though, right?
Did you go with 'orr'? Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: testing 'or' as a variable name

30 Nov 2019, 23:23

jeeswg wrote:
30 Nov 2019, 22:44
I feel for you with that very surprising, (no messages so) tough to debug error.
no messages on AHK_L 1.1
however, if the param is ByRef, you DO get an error on AHK Basic 1.0:

Code: Select all

ol := "a"
ot := "b"
or := "c"
ob := "d"
MsgBox, % MyFunc(ol, ot, or, ob)
return

MyFunc(byref one, byref two, byref three, byref four)
{
}
when i saw that error i thought maybe i had some weird unicode encodings in my file, and tried to convert the file to ansi codepage and messed around with that for a bit :crazy:


jeeswg wrote:
30 Nov 2019, 22:44
A good a-ha moment when you realised though, right?
Did you go with 'orr'? Cheers.
i went with 'orr' temporarily and then just went with 'offsetRight'

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: testing 'or' as a variable name

30 Nov 2019, 23:46

Ah, interesting!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Hansielein, Lpanatt and 317 guests