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 

can you modularize scripts with subroutines?

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



Joined: 17 Aug 2004
Posts: 2
Location: Grand Rapids Michigan

PostPosted: Tue Aug 17, 2004 1:09 pm    Post subject: can you modularize scripts with subroutines? Reply with quote

I don't see on the wish list or elsewhere..
I could be just blind.
so 2 questions, the first most important:


1 How can you best modularize your scripts?
2 Is there the concept of subroutines and different levels of visibility for variables?

Thanks
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10471

PostPosted: Tue Aug 17, 2004 1:53 pm    Post subject: Reply with quote

Since all variables and subroutines are global, in a large or complex script it is usually best to use semi-unique variable names to reduce the possibility of bugs and side-effects.

To call a subroutine in a way that mimics passing parameters and receiving a return value, I find this convention useful:

; Set input "parameters" by using a prefix/acronym to indicate who they're for.
; GCE stands for "GetColorExists":
GCE_x1 = 30
GCE_x2 = 50
GCE_y1 = 0
GCE_y2 = 200
Gosub, GetColorExists
MsgBox The subroutine's output is %ColorExists%.
return

GetColorExists:
...
; Set the output for the caller using the var name indicated by the subroutine's name:
ColorExists = y
...
return
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Tue Aug 17, 2004 4:44 pm    Post subject: Reply with quote

OK.. I thought that might be the case.. your suggestions are appropriate.. thanks for penning them!

Jeff
Back to top
Guest






PostPosted: Wed Aug 18, 2004 10:00 am    Post subject: Reply with quote

I find passing parameters a bit long winded. Would it be worth adding something on the wish-list to be able to parameterize the gosub. Maybe something like

Code:
gosub, calculate, 5, 10, %total%
msgbox, the answer is %total%
Return

calculate, v1, v2, v3:
  v3 = v1
  v3 += v2
Return


Not sure if it would be possible but certainly desirable! It would be good if v1 was just local to the subroutine but not essential.
Back to top
Guest






PostPosted: Wed Aug 18, 2004 10:33 am    Post subject: Reply with quote

Sorry - guess the above belongs in the wishlist Forum I have added it in there!
Back to top
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