Different behavior from IniRead to in-script values

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Noo0B
Posts: 151
Joined: 26 Jan 2018, 19:54

Different behavior from IniRead to in-script values

22 Aug 2018, 06:38

Hello,
This code behaves differently if the values were loaded through IniRead or from variable input.
Like so:

Code: Select all

SetWorkingDir %A_ScriptDir%
IniRead, Hk, Config.ini, Values, Hk
IniRead, XT, Config.ini, Values, XT
IniRead, FrameTime, Config.ini, Values, FrameTime
IniRead, HKey%Hk%XTDI%XT%, Config.ini, Values, HKey%Hk%XTDI%XT%
Msgbox % Hk " " XT " " FrameTime " " HKey%Hk%XTDI%XT%
Hk=1
XT=1
FrameTime=5000
HKey1XTDI1=%FrameTime%
Msgbox % Hk " " XT " " FrameTime " " HKey%Hk%XTDI%XT%
Here's Config.ini:

Code: Select all

[Values]
Hk=1
XT=1
FrameTime=5000
HKey1XTDI1=%FrameTime%
Does anyone have any Idea why IniRead fails in this code?
Thanks in advance,
Kind regards.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Different behavior from IniRead to in-script values

25 Aug 2018, 09:38

Code: Select all

SetWorkingDir %A_ScriptDir%
IniRead, Hk, Config.ini, Values, Hk
IniRead, XT, Config.ini, Values, XT
IniRead, FrameTime, Config.ini, Values, FrameTime
IniRead, HKey%Hk%XTDI%XT%, Config.ini, Values, HKey%Hk%XTDI%XT%
HKey1XTDI1 var is created, contains string literal: %FrameTime%. Basically what u have is this:

Code: Select all

; HKey1XTDI1 := "%FrameTime%"
; or if u will:
; HKey1XTDI1 = `%FrameTime`%
; which is not the same as
; HKey1XTDI1 = %FrameTime% ; which dereferences the var FrameTime, grabbing its contents
in the msgbox(forced expression mode, cause of the % sign) ure already double-dereferencing HKey%Hk%XTDI%XT% once to get to HKey1XTDI1, then the expression mode resolves HKey1XTDI1 to the string %FrameTime% and thats the end of it.
Noo0B
Posts: 151
Joined: 26 Jan 2018, 19:54

Re: Different behavior from IniRead to in-script values

26 Aug 2018, 04:48

Thanks for the reply.
That's what the message box shows.
`% shouldn´t be the case, since it's the same literal string on both Msgbox codes.
Changing %FrameTime% to FrameTime on the .ini file then so made no difference.
I also changed the In-script values Msgbox code to add an extra deref, but it still works:

Code: Select all

SetWorkingDir %A_ScriptDir%
IniRead, Hk, Config.ini, Values, Hk
IniRead, XT, Config.ini, Values, XT
IniRead, FrameTime, Config.ini, Values, FrameTime
IniRead, HKey%Hk%XTDI%XT%, Config.ini, Values, HKey%Hk%XTDI%XT%
Msgbox % Hk " " XT " " FrameTime " " HKey%Hk%XTDI%XT%
Hk=1
XT=1
FrameTime=5000
HKey%Hk%XTDI%XT%=FrameTime
Msgbox % Hk " " XT " " FrameTime " " HKey%Hk%XTDI%XT%
Still, no deref with IniRead values.
Thanks again.
Regards.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Different behavior from IniRead to in-script values

26 Aug 2018, 10:51

swagfag wrote:... and thats the end of it.
the point being u can at the very most dereference a variable twice. To do what u want in the way that u want, ud need to dereference it three times(which u cant to the best of my knowledge and even if u could it would be the 'best practice' solution to ur overall initial issue):
1. Deref %Hk% and %XT% in HKey%Hk%XTDI%XT% to obtain HKey1XTDI1
2. MsgBox's forced expression derefs HKey1XTDI1 to obtain FrameTime(ud need to remove the % signs from the config.ini or else this wouldnt even work at all)
3. Somehow(ie, using 2x %) deref FrameTime a third time to obtain 5000(which u cant do all in one step)

effectively ud need this nested deref abomination:

Code: Select all

MsgBox % %HKey%Hk%XTDI%XT%%
;             ^  ^    ^  ^		derefs to 1
;        ^                ^		derefs to FrameTime
;      ^ 						derefs to 5000
Noo0B
Posts: 151
Joined: 26 Jan 2018, 19:54

Re: Different behavior from IniRead to in-script values

27 Aug 2018, 05:05

I guess there must be a difference between an active script variable and a value loaded from the file.
The variable probably derefs at activation.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CuriousDad, Google [Bot], rc76 and 230 guests