AutoHotkey Community

It is currently May 27th, 2012, 4:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: June 21st, 2011, 9:10 pm 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
AHK_L v1.1.00.00 unicode x32

hi
here is a code
Code:
#persistent

call()
return

call()
{
   string := "11 11 1 3 4 5"
   stringsplit,p,string,%A_Space%
   msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
   settimer,test,-1
   return
   
   test:
      string := "11 11 1 3 4 5"
      stringsplit,p,string,%A_Space%
      msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
      return
}

The first msgBox works correctly, where the second one don't - it shows nothing
The following code work fine though:
Code:
#persistent

call()
return

call()
{
   global
   string := "11 11 1 3 4 5"
   stringsplit,p,string,%A_Space%
   msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
   settimer,test,-1
   return
   
   test:
      string := "11 11 1 3 4 5"
      stringsplit,p,string,%A_Space%
      msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
      return
}

won't believe it is something intended...

[Moved from Bug Reports. ~jaco0646]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2011, 10:39 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
The function hits the return & clears the variables. Besides making the function global, you could either put a sleep after SetTimer, or make the p1-p6 variables static.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2011, 10:45 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
No, you missed it. The subroutine sets the value of string again, making this a very odd bug.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2011, 11:14 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
AHK Documentation wrote:
When a function is entered by a subroutine thread, any references to dynamic variables made by that thread are treated as globals (including commands that create arrays).

This includes the StringSplit command. These comments should help understand:

Code:
#persistent

call()
return

call()
{
   string := "11 11 1 3 4 5"
   stringsplit,p,string,%A_Space%
   msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
   settimer,test,-1
   return ; p0 array cleared locally before subroutine execution
   
   test:
      string := "11 11 1 3 4 5" ; local
      stringsplit,p,string,%A_Space% ; creates global array
      msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " " ; local
      return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2011, 12:00 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
oh lol
isn't that a subset of the Extremely most very often common source of confusion ?

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2011, 4:30 pm 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
thanks, guys


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2011, 11:34 am 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
still don't understand why this won't work
Code:
#persistent

call()
return

call()
{
   settimer,test,-1
   return
   
   test:
      string := "11 11 1 3 4 5"
      stringsplit,p,string,%A_Space%
      msgbox % p1 " " p2 " " p3 " " p4 " " p5 " " p6 " "
      return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2011, 11:52 am 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
i think string split should be changed to return array object, not a old-form array, like this:
Code:
#persistent

call()
return

call()
{
   settimer,test,-1
   return
   
   test:
      string := "11 11 1 3 4 5"
     p := StrSplit(string," ")
      msgbox % p[1] " " p[2] " " p[3] " " p[4] " " p[5] " " p[6] " "
      return
}

StrSplit(str,delim)
{
   stringsplit,r,str,% delim
   ra := Array()
   loop, % r0
      ra.Insert(r%A_Index%)
   return ra
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2011, 3:27 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
better performance with this: (untested)
Code:
StrSplit(str, del){
   re := Array()
   Loop Parse, str, %del%
     re.Insert(A_LoopField)
   return re
}
or maybe this
Code:
StrSplit(str, del){
   re := Array()
   Loop Parse, str, %del%
      re[A_Index] := A_LoopField
   return re
}
Rather than using two loops.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, rbrtryn and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group