AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Weird function - parameter issue

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Thu Jun 28, 2007 7:02 pm    Post subject: Weird function - parameter issue Reply with quote

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
View user's profile Send private message
mwharri



Joined: 15 Mar 2007
Posts: 70

PostPosted: Thu Jun 28, 2007 7:06 pm    Post subject: Reply with quote

take the %'s off
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Thu Jun 28, 2007 7:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jun 28, 2007 7:19 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Thu Jun 28, 2007 7:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
daonlyfreez



Joined: 16 Mar 2005
Posts: 745
Location: Berlin

PostPosted: Thu Jun 28, 2007 7:50 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group