Strange situation: "++" VS "+1"
Posted: 07 Aug 2020, 12:19
Hi there,
I would like to ask someone to share some guidelines for differentiating dynamic variable definitions and pseudo-arrays.
After many hours of debugging my script I've removed most of the code just to find out a strange situation: depending on variable operation the script either fails or succeeds to perform a task. Here's the code:
You can see that this script closes the window on the Enter keypress, but it fails to do so if one comments out the line "imgGuiId++" and uncomments "imgGuiId := imgGuiId + 1". There should be no difference whether one uses "++" or "+1". I think the problem is, that in one case "hGuiName%A_Index%" is interpreted as a dynamic variable, and in the other - as a pseudo-array. How can I be sure which case is it? And why just by changing the operation syntax from "+1" to "++" I can influence this?
My question is specifically related only to this situation of swapping those code lines - the rest of the code (with dynamic variables) performs as expected (within the rest of the script).
Please, share some thoughts
I would like to ask someone to share some guidelines for differentiating dynamic variable definitions and pseudo-arrays.
After many hours of debugging my script I've removed most of the code just to find out a strange situation: depending on variable operation the script either fails or succeeds to perform a task. Here's the code:
Code: Select all
#SingleInstance Force
Global imgGuiId
If imgGuiId == ""
imgGuiId := 0
;; --------------------------- CASE: "++" VS "+1"
;; imgGuiId := imgGuiId + 1
imgGuiId++
;; ---------------------------
Gui guiName%imgGuiId%:New, +HWNDhGuiName%imgGuiId% ;; hGuiName1
Gui guiName%imgGuiId%:Add, Button, +Default +W50 +H20 +GguiName_Enter, ok
GuiControl Hide, ok
Gui guiName%imgGuiId%:Show, w200 h150
Return
guiName_Enter:
Global imgGuiId
WinGet actWndId, ID, A
Loop % imgGuiId
;; ---------------------------
;; WHEN "imgGuiId := imgGuiId + 1" is used: FAILS to read "hGuiName%A_Index%" as "hGuiName1" and returns
;; WHEN "imgGuiId++" is used: SUCCEEDS to read "hGuiName%A_Index%" as "hGuiName1" and closes the gui
If (actWndId == hGuiName%A_Index%)
Gui guiName%A_Index%:Destroy
;; ---------------------------
Return
Esc::ExitApp
My question is specifically related only to this situation of swapping those code lines - the rest of the code (with dynamic variables) performs as expected (within the rest of the script).
Please, share some thoughts