| View previous topic :: View next topic |
| Author |
Message |
kishjeff
Joined: 17 Aug 2004 Posts: 2 Location: Grand Rapids Michigan
|
Posted: Tue Aug 17, 2004 2:09 pm Post subject: can you modularize scripts with subroutines? |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Tue Aug 17, 2004 2:53 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Tue Aug 17, 2004 5:44 pm Post subject: |
|
|
OK.. I thought that might be the case.. your suggestions are appropriate.. thanks for penning them!
Jeff |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 18, 2004 11:00 am Post subject: |
|
|
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
|
Posted: Wed Aug 18, 2004 11:33 am Post subject: |
|
|
| Sorry - guess the above belongs in the wishlist Forum I have added it in there! |
|
| Back to top |
|
 |
|