Sign in to follow this  
Followers 0
marko001

Help with ProcessExists()

6 posts in this topic

Hi all.

Please can you help me with this?

The problem i have is that i always get a $processpid=ProcessExists($PIDGame) = 0 , but the $pidgame is <>0. ( i mean, the GAME IS up!)

What i want is to wait until the game spawns (become active) then continuing loop. I want to avoid to use sleep(15000), i prefer a structured solution:

while 1

bla bla bla

_launch(1)

_gameup(1)

_start(1)

bla bla bla

wend

func _launch($i)

Select

case $i=1

$tempname = StringTrimRight($s_gamepath1,4)

$tempname2 = $tempname & " /driver:" & $s_gamedriver

$PIDgame1=Run($tempname2,$s_g1folder, @SW_MAXIMIZE)

sleep(15000) (if i want it to work i need to use that! but i don't like)

_Gameup($i)

case $i=2

$tempname = StringTrimRight($s_gamepath2,4)

$tempname2 = $tempname & " /driver:" & $s_gamedriver

$PIDGame2=Run($tempname2,$s_g2folder, @SW_MAXIMIZE)

sleep(15000)

_Gameup($i)

EndSelect

EndFunc

func _gameup($k)

local $wait

$wait = 1

While $wait <>0

if $k=1 Then

$processpid=ProcessExists($PIDGame1) And i always get 0!!!

if $processpid = 0 then

$wait = $wait + 1

Else

$wait = 0

EndIf

ElseIf $k=2 Then

$processpid=ProcessExists($PIDGame2)

if $processpid = 0 then

$wait = $wait + 1

Else

$wait = 0

EndIf

EndIf

if $wait = 500 Then

$wait = 0 (only way to exit)

EndIf

WEnd

_status($k,"Game" & $k & " is up!")

EndFunc

Thanks a lot,

Marco

Share this post


Link to post
Share on other sites



Have you looked at ProcessWait ?

$PIDgame1=Run($tempname2,$s_g1folder, @SW_MAXIMIZE)
ProcessWait ($tempname2,15)

Share this post


Link to post
Share on other sites

Have you looked at ProcessWait ?

$PIDgame1=Run($tempname2,$s_g1folder, @SW_MAXIMIZE)
ProcessWait ($tempname2,15)
i tried. In fact it works but doesn't solve my problem since the game need few seconds before spawning but the

become =1 as soon as i run the game.

That means (correct me if i'm wrong) that in any case i need to give a sleep (15000) ...

Correct?

Marco

Share this post


Link to post
Share on other sites

Between the time that the process is spawned and the game is ready there is a period of some time, correct?

Would you be able to wait for a specific control to appear when the game was ready?

Could you use ProcessWait until the process is created and then pause the script until a specific control or window title becomes available?

Share this post


Link to post
Share on other sites

Between the time that the process is spawned and the game is ready there is a period of some time, correct?

Would you be able to wait for a specific control to appear when the game was ready?

Could you use ProcessWait until the process is created and then pause the script until a specific control or window title becomes available?

Yes this could help me. In fact once launched it takes around 10 secs before spawning. How can i check (and continue script) when the game window is spwned?

Share this post


Link to post
Share on other sites

If you can get the title of the game window when it is ready, you could use that with WinWaitActive()

Do
Until WinExists ( "Untitled - Notepad" )

WinWaitActive("Untitled")

You could also wait until a window no longer exists with:

WinWaitNotActive("Untitled")

You may want to check out AutoItSetOption and WinWaitDelay, as well.

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  
Followers 0