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 

Use independent scripts in one file?

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



Joined: 30 Jul 2004
Posts: 74
Location: Deutschland (sorry for my english)

PostPosted: Fri Nov 21, 2008 10:31 pm    Post subject: Use independent scripts in one file? Reply with quote

Hi all
i am asking for your help:

i have an file with an few scripts in it:

Code:
IF 1 = abc Gosub abc
IF 1 = def Gosub def
IF 1 = xyz Gosub xyz


abc:
;doit
def:
;doit
xyz:
;doit



Here i got an problem if i call this script with 'def'
and the code by 'abc' is something wrong or miss an var or like this...
then i got an error message for an block of code i didn't want
to use in that moment... because i need code 'def' right yet,
Code 'abc' will work in an other situation.


Now my question:
how can i set this code blocks separately in one single ahk-file?
So if i call one block while an other block is not valid right now
i don't want to get an error message for this non-valid block.


Any hints please?
_________________
Stefan

This post was created with the kindly help of http://dict.leo.org/ and remember: “Allways look on the bright side of Life”
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Nov 21, 2008 10:54 pm    Post subject: Reply with quote

Try How to: Run Dynamic Script... Through a Pipe!

You could have several scripts each stored a separate variable and run them as you like.
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink


Last edited by HotKeyIt on Sat Nov 22, 2008 2:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
Stefan



Joined: 30 Jul 2004
Posts: 74
Location: Deutschland (sorry for my english)

PostPosted: Fri Nov 21, 2008 11:56 pm    Post subject: Reply with quote

Thank you

i found the thread you mention under this URL:
http://www.autohotkey.com/forum/viewtopic.php?t=25867

but i don't see how this could help me.
_________________
Stefan

This post was created with the kindly help of http://dict.leo.org/ and remember: “Allways look on the bright side of Life”
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Sat Nov 22, 2008 3:04 pm    Post subject: Reply with quote

In this case please explain your problem.

With dynamic scripting you can run several scripts from one file, each can be executed separately or even together.
E.g.:
Code:

Script1 =
(
   a = FIRST
   MsgBox This is the `%a`% Script
   
)
Script2 =
(
   MsgBox This is the SECOND Script``nContent of a = `%a`%
   
)
SetTimer, ChangeButtons, -50
MsgBox, 262147, Select script, Witch script would you like to run?
IfMsgBox Yes
{
   #__RUN_TEMP_SCRIPT(script1, "Your first script")
}
else IfMsgBox No
{
   #__RUN_TEMP_SCRIPT(script2, "Your second script")
}
else IfMsgBox Cancel
{
   #__RUN_TEMP_SCRIPT(script1 . script2, "Both Scripts in one")
}
ExitApp

ChangeButtons:
WinWait, Select script AHK_class #32770
ControlSetText, Button1, Script1, Select script AHK_class #32770
ControlSetText, Button2, Script2, Select script AHK_class #32770
ControlSetText, Button3, Run Both, Select script AHK_class #32770
WinActivate, Select script AHK_class #32770
Return

#__RUN_TEMP_SCRIPT(script, scriptname="")
{
   If scriptname =
      #__PIPE_NAME_ := A_TickCount
   else
      #__PIPE_NAME_ := scriptname
   #__PIPE_GA_ := CreateNamedPipe(#__PIPE_NAME_, 2)
   #__PIPE_    := CreateNamedPipe(#__PIPE_NAME_, 2)
   if (#__PIPE_=-1 or #__PIPE_GA_=-1) {
      MsgBox CreateNamedPipe failed.
      Return
   }
   Run, %A_AhkPath% "\\.\pipe\%#__PIPE_NAME_%"
   DllCall("ConnectNamedPipe","uint",#__PIPE_GA_,"uint",0)
   DllCall("CloseHandle","uint",#__PIPE_GA_)
   DllCall("ConnectNamedPipe","uint",#__PIPE_,"uint",0)
   script := chr(239) . chr(187) . chr(191) . script
   if !DllCall("WriteFile","uint",#__PIPE_,"str",script,"uint",StrLen(script)+1,"uint*",0,"uint",0)
      MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
   DllCall("CloseHandle","uint",#__PIPE_)
   Return #__PIPE_NAME_
}
CreateNamedPipe(Name, OpenMode=3, PipeMode=0, MaxInstances=255) {
   return DllCall("CreateNamedPipe","str","\\.\pipe\" Name,"uint",OpenMode
      ,"uint",PipeMode,"uint",MaxInstances,"uint",0,"uint",0,"uint",0,"uint",0)
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Display posts from previous:   
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