Jump to content
Sign in to follow this  
Jfish

Problems with running multiple scripts

Recommended Posts

Jfish

Hello all,

Your resident newbie friend JFish here ... was hoping I could get some help from some folks. I apologize in advance if this is a dumb question. I have some code that creates a shuttlelist of au3 scripts and places select scripts on a playlist. It will then execuet the au3 files sequentially in a loop for a user designated number of times. I am using this code snippet to run the scripts from an array:

ShellExecuteWait("AutoIt3.exe",$SCRIPTARRAY[$a][0],$scriptPath)

Some of the scripts may look for windows. If a window is not there I would like the script to ContinueLoop or Exit. However, those commands can only be used from inside the loop. In my case, the "script player" is creating the loops when it plays the au3 files so that does not work. You should also know that the scripts being played look for a timeout if a window is not there and capture the result like so (where _logError just writes to a file saying it failed):

WinWait("Untitled - Notepad","",1)

If Not WinActive("Untitled - Notepad","") Then WinActivate("Untitled - Notepad","")

dim $var1 = WinWaitActive("Untitled - Notepad","",1)

if $var1=0 then

_logError()

Exit

EndIf

That timeout capture code could obviously be anything. Having said that, is there a way I can get the script being played to interact with the script playing it so that I can ContinueLoop on the player (as opposed to the playee)? Said another way, how can I get the script being played to communicate with the player? I was thinking of TCP - if I were to use that and make the player a server with the scripts acting as clients would the player recognize a message in the middle of an action that is playing one of the of au3 files? Also, please feel free to tell me I am way off track. I confess I am bit lost at the moment.

I realize that is a lot - hope it made sense - any help would be greatly appreciated.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Jfish

You could use WM_COPYDATA messages.

Search for them on the forum, many different uses have been posted.

:)

PsaltyDS:

That looks very promising. Thank you very much for pointing me in the right direction. I will see if I can get it to work.

Thanks again.

JFish


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Authenticity

Try something like this concept but less dumb :)

Parent:

Opt('MustDeclareVars', 1)

Dim $oShell, $oEnv, $Test, $sPath

$oShell = ObjCreate('WScript.Shell')
$oEnv = $oShell.Environment('Volatile')
$sPath = @ScriptDir & '\Test.exe'

ShellExecuteWait($sPath)

; Get the volatile variable value
$Test = $oEnv('IWant')

MsgBox(0x40, 'Title', $Test)oÝ÷ Ø(bÔÞ²Ö®ßbr¬r©WmçºÇ¨~Ø^mèZ¾*+¡ûa{
Ú¦«èZºÚ"µÍÜ
    ÌÎNÓ]ÝXÛUÉÌÎNËJB[H ÌÍÛÔÚ[ ÌÍÛÑ[   ÌÍÒUØ[ÌÍÛÔÚ[HØÜX]J   ÌÎNÕÔØÜÚ[    ÌÎNÊBÌÍÛÑ[H  ÌÍÛÔÚ[[ÛY[
    ÌÎNÕÛ][IÌÎNÊBÌÍÒUØ[H[Q^ÝÊ  ÌÎNÐÎÌLÕÒS   ÌÎNÊBY   ÌÍÒUØ[[IÌÍÛÑ[   ÌÎNÒUØ[ ÌÎNÊHH   ÌÎNÖYÈHØ[  ÌÎNÂ[ÙBIÌÍÛÑ[   ÌÎNÒUØ[ ÌÎNÊHH   ][ÝÓÈHÛÌÎNÝØ[   ][ÝÂ[Y^]

Share this post


Link to post
Share on other sites
jvanegmond

Using TCP to send data to yourself on the loopback address is not a bad solution either. It can be quite straightforward to implement this, especially if you already know how TCP works.

Share this post


Link to post
Share on other sites
Jfish

:) Okay, I have been reviewing all these excellent ideas, reading all the strings, and trying to figure out the best way to solve this given that I have super-Newb status and find some of these hard to implement. $WM_DATA looks very cool but I don't really understand DLL calls and the C/C++ concepts behind the creation of structures. TCP seems great but I am not all that familiar with it. In my forum travels I did come accross an interesting idea from PsaltyDS dealing with passing information via GUIs: http://www.autoitscript.com/forum/index.php?showtopic=44167. I think this may be a great way for a newbie like me to be able to create an invisible GUI (this example is visible) that starts with the player and has the player script and the playee script reading and writing from an intermediary "receiver". Here is what I mean...(must compile 2 of 3 since scite won't run mulitple au3 files):

The sender:

CODE

;guiExhange - this will create a gui that will hold information to be passed between two application

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\rc01712\desktop\scriptrunner1.3.2\guiexchange\sender.kxf

$Form1_1 = GUICreate("Sender", 312, 88, 193, 125)

$sendString = GUICtrlCreateInput("", 40, 16, 241, 21)

$send = GUICtrlCreateButton("Send", 96, 48, 105, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

case $send

local $textToSend = GUICtrlRead($sendString)

local $msgHandle = ControlGetHandle("Receiver","","[CLASS:Static; INSTANCE:1]")

ControlSetText("Receiver","",$msgHandle,$textToSend)

local $msgHandle = ControlGetHandle("Receiver","",$textToSend)

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

The "receiver"

CODE
#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\rc01712\desktop\scriptrunner1.3.2\guiexchange\receiver.kxf

$Form2_1 = GUICreate("Receiver", 406, 118, 217, 143)

$message = GUICtrlCreateLabel("Message", 56, 24, 200, 17)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

And finally, the reader:

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\rc01712\desktop\scriptrunner1.3.2\guiexchange\reader.kxf

$Form2 = GUICreate("reader", 337, 191, 303, 219)

$messageLabel = GUICtrlCreateLabel("Message from receiver:", 48, 24, 114, 17)

$readMessage = GUICtrlCreateLabel("readMessage", 48, 72, 200, 17)

$readMsg = GUICtrlCreateButton("readMsg", 264, 16, 57, 33, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $readMsg

local $msgHandle = ControlGetHandle("Receiver","","[CLASS:Static; INSTANCE:1]")

Local $readText = ControlGetText("Receiver","",$msgHandle)

controlSetText("","",$readMessage,$readText)

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

This example shows that I can get one script to set the information on another window to be read by another script without using TCP or anything like that. I think PsaltyDS had a great idea with his original post. Does anybody see any reason why this would not work? I could say something like:

(pseudo - code)

read from the reader

if message = failuer then

ContinueLoop

reset message on receiver to "okay"

else

shellexecutewait(the next script)

Thoughts?


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
PsaltyDS

I think PsaltyDS had a great idea with his original post. Does anybody see any reason why this would not work?

It's brilliant! Any penguin that good looking must know what he's talking about... :)

You don't need a whole hidden GUI though, it can just be a hidden edit control on the main visible GUI.

:lmao:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Jfish

It's brilliant! Any penguin that good looking must know what he's talking about... :)

You don't need a whole hidden GUI though, it can just be a hidden edit control on the main visible GUI.

:lmao:

Thanks PsaltyDS for the refinement. One hidden control is much better than a whole new hidden window.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.