Jump to content


Photo

Array%index% doesn't work in label inside a function


  • Please log in to reply
1 reply to this topic

#1 Peter

Peter
  • Members
  • 448 posts

Posted 26 August 2006 - 05:04 PM

I started the topic in Help section, but I fear it's a bug.
I combine a string with a variable content, to assign a new variable (kind of array), like this: New_Variable:= %Variable%String.
It works, except when I make it in a label that's inside a function.
NewVar()
   F9::ExitApp
Return
NewVar()
{
   Static TestVar,Index
   Index= Test
   TestVar= {esc}

   VarToMake:= %Index%Var  ; -> content of VarToMake is {esc}
   MsgBox, 0, TestVar= %TestVar%, 1: VarToMake= %VarToMake%
   SetTimer, TimerLabel, 1000
   Return
TimerLabel:
   SetTimer, TimerLabel, off
   VarToMake:= %Index%Var  ; identical expression, but different result (empty)
   MsgBox, 0, TestVar= %TestVar%, 2: VarToMake= %VarToMake%
Return
}
It's only when jumping to the label that the empty VarToMake variable occurs, not when coming back to the function in a normal way.

#2 Chris

Chris
  • Administrators
  • 10727 posts

Posted 27 August 2006 - 04:56 PM

This behavior is intentional due to the limitations of the architecture (and the fact that subroutines inside a function weren't originally intended to be callable from outside it -- that was an accident whose benefits seemed worth keeping).

I've added the following to the documentation to clarify it: "When a function is entered by a subroutine thread, any references to dynamic variables made by that thread are treated as globals."

By the way, this issue is related to your other bug report "Crash with SysGet in label inside function", which has been fixed in today's release (thanks for reporting it).