Jump to content
Snuwy

Combine 2 Script to work in the same time

Recommended Posts

Snuwy

HotKeySet("{F6}", "Pause")
HotKeySet ("{F5}", "Starts")
HotKeySet ("{F10}", "Exits")

While 1
   Sleep (200)
   WEnd

Func Exits ()
   Exit
   EndFunc


Func Starts ()
While 1
Send("aaaa")
Sleep(300)
WEnd
EndFunc


Func Pause ()
   While 1
   Sleep (200)
   Wend
   EndFunc

 

HotKeySet("{F6}", "Pause")
HotKeySet ("{F5}", "Starts")
HotKeySet ("{F10}", "Exits")

While 1
   Sleep (200)
   WEnd

Func Exits ()
   Exit
   EndFunc


Func Starts ()
While 1
Send("bbbbb")
Sleep(500)
WEnd
EndFunc


Func Pause ()
   While 1
   Sleep (200)
   Wend
   EndFunc


How To Combine those script in the same exe ? but when i press f5 the script will press aaaa bbbb

 

 

 

Share this post


Link to post
Share on other sites
water

What do you try to achieve with this script?
Which program do you try to automate?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Snuwy

What do you try to achieve with this script?
Which program do you try to automate?

​to learn something new

i don't use it on any program yet, but if i want 2 different script working the same time, i must click 2 exe.. and press different hotkeys,

exe 1 start = F5

exe 2 start = F4

So Both file 1 and 2 working the same time

but, how can you make those 2 files into 1 executable file with 1 hotkey press

if i combine script 2 and 1 like this

Func Starts ()
While 1
Send("aaaa")
Sleep(300)
WEnd
EndFunc

Func Starts ()
While 1
Send("bbbbb")
Sleep(500)
WEnd
EndFunc

the script got eror duplicate line

Share this post


Link to post
Share on other sites
water

Still don't get what you try to "learn".
It is very, very similar to the "problem" you posted in 2011. Did the answer work for you?
Nevertheless, check AdLibRegister in the help file.
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Snuwy

Still don't get what you try to "learn".
It is very, very similar to the "problem" you posted in 2011. Did the answer work for you?
Nevertheless, check AdLibRegister in the help file.
 

​>.< my english still bad, it's different from what i post in 2011

maybe i use pixel search in my explanation

i have 2 script, snuwy1.au3 and snuwy2.au3

i run script

snuwy1 search pixel blue when found the script play music a and sleep 3 min

snuwy2 2 search pixel red when found the script play music b and sleep 3 min

how can you mix that 2 script into only 1 script working.. example snuwy.au3 = snuwy1.au3+snuwy2.au3

or maybe in snuwy.au3 thereis a script that = script in snuwy1.au3 and snuwy2.au3 working in the same time..

if i combine the script in 1 file the script not run in the same time, but will wait until snuwy1.au3 done and do snuwy2.au3

 

Edited by Snuwy

Share this post


Link to post
Share on other sites
water

That's why I suggested function AdLibRegister.

When you say PixelSearch, do you try to automate an ordinary program or a game?
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Snuwy

I used PixelSearch mostly for game, it's just example

i read the adlibregister. so if i want snuwy1 and snuwy2 working i just add

Func Starts()
   
    AdlibRegister("Snuwy1")
    AdlibRegister("Snuwy2")
 
EndFunc

did adlibregister need while 1 and wend ?

Edited by Snuwy

Share this post


Link to post
Share on other sites
Melba23

Snuwy,

I used PixelSearch mostly for game, it's just example

It might just be an example, but please read the Forum rules - particularly the bit about not discussing game automation - before you post again.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
TheBrainiac

The original question seems innocent enough. I'll have a stab at it:

If I'm not mistaken, you have two sets of functions that you'd like to merge into the same script, and you want one hotkey to run both registered functions, i.e. when you press F5, the script should run both Starts() functions you wrote.

As far as I'm aware, a key combination can only be bound to one function at a time, even across multiple scripts. The easiest solution is to merge both function bodies into one:

 

Func Starts ()

While 1
Send("aaaa")
Sleep(300)
WEnd


While 1
Send("bbbb")
Sleep(500)
WEnd

EndFunc

 

or bind the hotkey to a new function that calls the original ones:

 

HotKeySet("{F5}", "Starts")

Func Starts()
    Starts1()
    Starts2()
EndFunc

Func Starts1() 
    While 1
        Send("aaaa")
        Sleep(300)
    WEnd
EndFunc

Func Starts2()
    While 1
        Send("bbbb")
        Sleep(500)
    WEnd
EndFunc

(Of course you need exit conditions, but we're only talking examples here.)

If you want both functions to be executed at the same time, you will have to either interweave the code so that the two functions proceed in an alternating fashion:

While 1
    Send("a")
    Sleep(300)
    Send("b")
    Sleep(500)
WEnd

(I call it 'pseudo-multithreading')

Or stick to two scripts, because AutoIt does not feature true multithreading.

 

Hope this helps!

 

Edit: Looking at your older post water mentioned, it looks like you don't really understand program flow yet. You cannot simply put two While 1 - WEnd loops after each other. Your script will get stuck in the first loop, because "While 1" translates to "Do this until the end of forever".

Furthermore, "Duplicate line" means you're trying to define two functions with the same name. This confuses the scripting engine, because it's like giving it two recipes for pie and then telling it to "make pie". It cannot decide which one to use. You need to give the two versions of your function two different names (Starts1 and Starts2), even at the cost of breaking the "symmetry" of your scripts.

Edited by TheBrainiac

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×