| View previous topic :: View next topic |
| Author |
Message |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Thu Jun 28, 2007 7:02 pm Post subject: Weird function - parameter issue |
|
|
I've got a function .. defined roughly as ..
;-----------------------------------------------------------------------------
Get_Tag(_tag, _parent="", _tagindex=-1, _start=-1 )
;-----------------------------------------------------------------------------
{
global
...
listvars
pause
}
and later call it with
Get_XML_Tag("MyTag1","MyTag2",%indexcount%)
where indexcount=3
but when I examine the vars inside the function -
_tagindex still is -1 (the default) when it should be 3 (the passed)
the others are OK (__tag=MyTag1 _parent=MyTag2 and _start=-1 the deefault).
why doesn't _tagindex=3 ? |
|
| Back to top |
|
 |
mwharri
Joined: 15 Mar 2007 Posts: 70
|
Posted: Thu Jun 28, 2007 7:06 pm Post subject: |
|
|
| take the %'s off |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Thu Jun 28, 2007 7:11 pm Post subject: |
|
|
ugh .. you're right ...
however, for the record ... the use of %, quotes, literals within functions is definitely not intuitive and dare I say quirky - especially when passing an array value array[%indexvar%] or using a function within a conditional. Seems these are where I most often see the weirdest debugging issues.
Thanks for the catching the % .... !! |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Jun 28, 2007 7:19 pm Post subject: |
|
|
if you always use expression forms of variable referencing, the % becomes alot less confusing.
AHK has slowly evolved from needing %var% to var in most circumstances. The only hard part is rembering when you are in expression mode, and when you are not.
anything inside parentheses is in expression mode, as is anything after := or a single % .
almost everything else is in non-expression mode, though some commands take %% and some don't. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Thu Jun 28, 2007 7:29 pm Post subject: |
|
|
I am glad that AHK is evolving (and quite happy with the rate and direction of the evolution)
there are some funky cases where the use of % etc sends me to the manual or to my working code for examples every time ... from recent memory I'd had issues when doing some compares between vars and arrays with % inside ... writing similar strings to fileappend or msgbox ... where I could not get the function or operation to work unless I created an interim _temp=... variable beforehand and using %_temp% inside fileappend or msgbox. No matter. it all eventually works.
Thanks again |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Thu Jun 28, 2007 7:50 pm Post subject: |
|
|
Just try to remember the "as-less-typing-as-necessary-rule".
It evolved from there, and sure can be confusing at times, but if you simply think of AHK as a handwritten coding-language, it will make sense. _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
|