#include only a part of the script included

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Oldboy
Posts: 19
Joined: 09 Aug 2018, 03:03

#include only a part of the script included

13 Dec 2018, 05:49

Hi, I was wondering if it's possible to include only a part of the script included.

For Example:
MAIN SCRIPT:
#include C:\SUBSCRIPT.apk

SUBSCRIPT:
msgbox, string 1

msgbox, string 2

msgbox, string 3

Is it possible to start the included script from msgbox, string 2 or msgbox, string 3?
Thanks in advice
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: #include only a part of the script included

13 Dec 2018, 09:37

If you make the subscript a bunch of functions then depending on what you have in the main script you could have the second string appear first. But it would have to be something like this

Code: Select all

MAIN SCRIPT:
#include C:\SUBSCRIPT.apk
function2(string)

SUBSCRIPT:
function1(string) {
	msgbox, string 1
}
function2(string) {
	msgbox, string 2
}
function3(string) {
	msgbox, string 3
}
You could also use the Run command to run the second script and pass a parameter, and use that parameter to say to skip the first one, but functions might be easier for you to use.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: #include only a part of the script included

13 Dec 2018, 12:46

Something like this perhaps, using GoSub. Cheers.

Code: Select all

MsgBox, % "1 auto-execute section"
GoSub MyLabel
return

MsgBox, % "x" ;not executed

MyLabel:
MsgBox, % "2"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Oldboy
Posts: 19
Joined: 09 Aug 2018, 03:03

Re: #include only a part of the script included

19 Dec 2018, 08:57

MannyKSoSo wrote:
13 Dec 2018, 09:37
If you make the subscript a bunch of functions then depending on what you have in the main script you could have the second string appear first. But it would have to be something like this

Code: Select all

MAIN SCRIPT:
#include C:\SUBSCRIPT.apk
function2(string)

SUBSCRIPT:
function1(string) {
	msgbox, string 1
}
function2(string) {
	msgbox, string 2
}
function3(string) {
	msgbox, string 3
}
You could also use the Run command to run the second script and pass a parameter, and use that parameter to say to skip the first one, but functions might be easier for you to use.
Thanks for the reply, unfortunately when I launch the script a messagge appear:
Line Text:function1(string)
Error: Parameters of hotkey functions must be optional.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: #include only a part of the script included

19 Dec 2018, 09:03

Sorry for the confusion, but they were meant to be separated like so
MAIN SCRIPT:

Code: Select all

#include C:\SUBSCRIPT.ahk
string := "this"
function2(string)
SUBSCRIPT:

Code: Select all

function1(string) {
	msgbox, string 1
}
function2(string) {
	msgbox, string 2
}
function3(string) {
	msgbox, string 3
}
Last edited by MannyKSoSo on 19 Dec 2018, 09:21, edited 1 time in total.
Oldboy
Posts: 19
Joined: 09 Aug 2018, 03:03

Re: #include only a part of the script included

19 Dec 2018, 09:10

Thank you again, I wrote them separately from the first time, but the error still remain
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: #include only a part of the script included

19 Dec 2018, 09:23

I have adjusted and tested it above and got it to work on my side. Make sure that the subscript.ahk file is in the exact location as stated in the includes (if it is in the same folder simply just state the subscript.ahk without any directory).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Ineedhelplz, mapcarter, peter_ahk, Rohwedder and 307 guests