Jump to content

better looping....


 Share

Recommended Posts

i have a script that i wrote that i am having trouble with.

here is an example of my problem.

$black = 0

while 1

call ("this")

call ("that")

call ("whatever")

call ("me")

call ("a cab")

wend

func this()

sleep(1000)

;does some stuff

endfunc

func that()

sleep(1000)

;does some stuff too

endfunc

func whatever()

sleep(1000)

;this does whatever

endfunc

func me()

sleep(1000)

;dont ask

endfunc

func a cab()

winsetstate("some window")

$color = pixelgetcolor(100,100)

if $color <> $black then

call ("this")

call ("that")

call (whatever")

call ("me")

call ("a cab")

endif

do

sleep (100)

until $color = $black

endfunc

the problem is..... it will basically "start over" by calling all of the functions again.

if $color <> $black.

BUT... once it gets to the end of recalling all the functions, the script resumes where it left off at the end of the "if" statement in the "a cab" function.

where as it will infinately go through the "do" loop and will never get to the end of the "while loop" and start over.

the real script is much bigger, but i had thought of simply adding $color = $black at the end of the "if" statement...

but the script does alot, and there are parts in EVERY function that will start from the beginning of the function calling order.... kind of hard to explain but.....

the script will detect an event and it will then "start over" by calling all the functions that are in the while loop before the function where the event occured, including the function itself.

once it has done that, there are still infinate loops in the function after the "if event occurs" part of the function that are waiting for events that will never happen, because the first three functions have not been called. so i pretty much call them, so the script can have one more loop before it crashes.

i want to just do it like this

call ("fixed")

func fixed()

$black = 0

while 1

call ("this")

call ("that")

call ("whatever")

call ("me")

call ("a cab")

wend

endfunc

func this()

sleep(1000)

;does some stuff

endfunc

func that()

sleep(1000)

;does some stuff too

endfunc

func whatever()

sleep(1000)

;this does whatever

endfunc

func me()

sleep(1000)

;dont ask

endfunc

func a cab()

winsetstate("some window")

$color = pixelgetcolor(100,100)

if $color <> $black then

call ("this")

call ("that")

call (whatever")

call ("me")

call ("a cab")

endif

do

sleep (100)

until $color = $black

endfunc

then just call the script over instead of calling each individual function.

but wont that eat up memory? because its basically keeping track of where it was previously in the script.... kind of like turning it into spaghetti...

whats the best way to do this.. i sure hope someone understands what i mean.. if not maybe you could ask me some questions.

thanks

T0ddie

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

i can only think of breaking up my functions into smaller functions.

and after calling the other functions, end that function. to "kill" the loop

man, thats it.. i cant think . im getting a beer. hey, i noticed valik is in the forums now.... man, i havent been insulted by him in awhile. i could use a good flaming.

EDIT: hello????

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Use the edit button please.

I don't understand what you're trying to do, I didn't read your entire post becuase I'm short on time. But I'll assume you're just trying to initiate the functions.

After looking over your functions they look like '1 time things,' only make something a function if you plan on possibly using it multiple times.

Calling a function looks like this:

FunctionName ( Parameters )

So to call one of your functions, I'd use this code:

This()

func this()
sleep(1000)
;does some stuff
endfunc

ALSO, please capitalize correctly and post code in the [ code ] tags.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

i have a script that i wrote that i am having trouble with.

I don't know if I fully understand, but, instead of the DO loop after calling "fixed",

;~ Call("fixed")

;~ Do

;~ Sleep(100)

;~ Until $color = $black

put the call inside of the DO loop. When color becomes black, the loop exits (see comment at function a_cab) (after your beer of course).

$black = 0

Do

Call("fixed")

Sleep(100)

Until $color = $black

Exit

Func fixed()

$black = 0

While 1

Call("this")

Call("that")

Call("whatever")

Call("me")

Call("a_cab")

WEnd

EndFunc ;==>fixed

Func this()

Sleep(1000)

;does some stuff

EndFunc ;==>this

Func that()

Sleep(1000)

;does some stuff too

EndFunc ;==>that

Func whatever()

Sleep(1000)

;this does whatever

EndFunc ;==>whatever

Func me()

Sleep(1000)

;dont ask

EndFunc ;==>me

Func a_cab ()

WinSetState("some window")

$color = PixelGetColor(100, 100)

That would mean you don't do this as it recursively calls itself. Let the DO loop check the color and recall all of the functions if necessary.

;~ If $color <> $black Then

;~ Call("this")

;~ Call("that")

;~ Call(whatever")

;~ Call("me")

;~ Call("a_cab")

;~ EndIf

EndFunc ;==>a_cab

Phillip

Link to comment
Share on other sites

i have cut out alot from this script, because i dont want my work to be copied really, but here is some of the script, the infinate while loop, and one of the functions.

it can explain better than i can

i have put this

;#####################################################

where the trouble spots are.

as soon as you look at the code, you will see what im talking about.

thanks

Copy_of_HIGH_ROLLER_.au3

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Sorry, some required files are missing, if you intended to view a topic, it's possible that it's been moved or deleted. Please go back and try again.

Philip is right, it's infinite because you never check the color again. You check it once, then you wait until the color is black, but it never checks any more becuase it's outside the Do loop.

Why do you want your script so private?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

i worked on it hard for countless hours.

plus, you dont NEED the whole script to see the problem. it would just waste space.

also...

i dont want my program to mess up a good thing, and give everyone else the same advantage that im using it for, if they play the game i play.

and that example i gave, is not a good example!!!! i dont know how to explain it.

let the code explain it. have a look.... the example i made in the post doesnt explain the problem correctly. you can see the problem from this snippet of my code

thanks

EDIT: you probably tried to download my code at the same time i was editing it, because i removed and reuploaded it. take a look now, its right there.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Works now, but I don't know where to look?

And I don't want to error check that entire thing -.-, could you just show us the problem area?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

i put ;#####################################################

where the problems are......

as you can see, in the same function, i call other functions using an if statement. they dont always get called, unless some event occurs.

but when that event occurs, it will call those functions, and then it will sit in whatever loop in the script comes next, because an event fails to take place because the script after calling those functions.... "starts out" in the middle of the function "resign" instead of starting at the beginning of the "while" loop

pretty much, if some event occurs, i would like to stop the while loop, and start it over. i cant do it though, and any workaround i try, is futile

does that clear it up anymore?

sorry, capitals are not my friends..

i try to use quotes and code tags, but have you seen my code?

its not worthy of such fine tools (actually, i just dont know how, and when i try i mess it up)

lol.. mmmmm beer

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

It just looks like you repeated the same lines over and over... why aren't you using a loop to do that...?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

the beginning of the script is a while loop, and it calls those functions.

then it repeats, as its infinate.

if no events occurred, to trigger the "if" statements that call the functions inside the functions, it would be great, but unfortunately, those events occur.

so, i am pretty much doing what the "while" loop does.... when an event occurs.in that function.

instead of routing the script back to the beginning of the while loop, (cant be done)

there is no goto command or any way i can think of to do it.

i just create another series of calling the functions that i need. but after they get called, instead of starting over like the "while" loop would, it keeps going where it left off in that function.

its in the middle of the resign function waiting for an event to occur, but it cant occur.because the script is not "in sync" with where it should be with the picture on the computer monitor.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

There's no need for a go to command.

Use something like this...

While Pixel = This AND Pixel = This 
  ;code to do while waiting
WEnd

Then do that for every thing you want, then throw that inside a loop so it does it all over again.

I think that's very simple...

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

i dont understand, i dont think you are getting my problem

for example...

my script goes through calling functions in an infinite while loop.

my script waits for a black color on the screen in one of the loops

if it waits for more than 5 minutes, something went wrong... meaning maybe my opponent timed out, or just refuses to play. either way...

i want to start the script over.

so i click the appropriate things on the screen to end the game, and i want to start it over...

but the script needs to start at the beginning now,(the beginning of the while loop) because that timer went off instead of the opponent "doing something"

so what i do is i call the same functions in the same order as in the beginning of the script (the while loop). and it works great, intill it gets to the end of the last function i called from within function resign. (function resign)

it just waits for an even thats supposed to happen normally each and every time, but it never happens because after the event occurs, it calls the functions in the same order as the while loop, but it doesnt repeat... there is no while wend. its an if and endif.

so it should be calling function endgame, but instead, after function resign... calls function resign.... endif..... it sits in a loop in the rest of the resign function thats supposed to occur after that if statement that checks for that event.

*********************IMPORTANT*************************

if that same function (function resign) was called from the while loop, and there was no event such as the timer reaching 5 minutes, it would call the next function that is after that. (function endgame in the while loop) BUT... im not calling it from the while loop this time, im calling it from inside the resign function.(because an event occured that made me want to make a new game, and start the process over )

********************************************************

the script is just a while loop.. and a bunch of functions that its calling.

if i ran a second script from the first script.... and that second script ended the first script if a certain event occured.. then started it back up again, that would solve my problem... but alas!

im trying to do it all in one script.

i dont know how to STOP EVERYTHING and go back to the very beginning of the script, i dont think its possible.

and at the beginning of the script, is the while loop if you recall... repeating calling functions over and over and over.

well, if i make it so when an event occurs, go into this while loop, thats like, while while.. and if it occurs again, its like while while while and again, its like while while while while.

do you know what i mean? that seems like it would use alot of cpu up and crash it eventually.

now, need i explain it further, with an even larger explanation?

do you get what im talking about?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

...k

Watch this:

While 1
   While 1
      JoinGame()
      If @error = 1 Then ExitLoop(1)
      AnotherFunc()
      If @error = 1 Then ExitLoop(1)
   WEnd
WEnd

If you don't understand a function hit the AutoIT help file.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

nesting......

i understand but man.... dude......!!!!

thats not what i need

its not an error that occurs, its an event******************************

and i dont want to exit the while loop, i want to exit the function that its stuck in the middle of and then "not call" the rest of the following functions in the while loop.

so if an event occurs in a function, RESTART the while loop that called the function.

(not exit the loop)

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

He knows a lot more au3 then you think.

<{POST_SNAPBACK}>

Obviously not or he wouldn't be asking for an answer to this simple problem. If he can't see the obviousness and correctness of the responses being posted, then I'm afraid he either needs to write better English to explain the problem better or write better code to avoid the problem. As far as I'm concerned, based on the (poor) description and (very poor) code, Insolence has given a correct solution.
Link to comment
Share on other sites

its partial code, and it looks funny i suppose to you. but thats ok.

im trying to explain a problem that i dont know how to fix. but i am aware its occuring.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...