Sign in to follow this  
Followers 0
Ham123

Looping functions and such.

25 posts in this topic

#1 ·  Posted (edited)

This is an excerpt from the code im writing.

Im sure it seems pretty ugly to those who are experts on this, but it satisfies me :)

What I am attempting to do is the following:

1.) func close will always work

2.) bb function will work once, then the other functions will follow through, only once a certain pixelgetcolor test has been confirmed will it use it again (included later in script)

3.) After bb function has happened, func c will happen, and then only once the pixelgetcolor is confirmed will it run the .exe

4.) after func c, the same thing with func d.

5.) after func d has occured, and a pixelgetcolor has been confirmed, cal.exe will run, and once it has completed, i would like it to continue testing a pixelgetcolor until the pixelgetcolor has occured involving bb will it stop.

So the thing i am having trouble with. How to make Func cal() looping only when a certain pixelgetcolor is confirmed, and after that, a different pixelgetcolor which will make the whole loop go back to Func bb?

Would I do:

CODE

Func cal()

While pixelgetcolor( x, y) <> 0x...... Then

Wend

Else

run( "cal.exe" )

Endfunc

Func return()

If pixelgetcolor( x, y) = 0x......... Then

(command to return to func bb?)

Else

(command to return to func cal?)

Endfunc

the code that i am attempting :party:

CODE

Func Close()

Exit

EndFunc

Func bb()

Run( "z.exe" )

EndFunc

Func c()

While PixelGetColor( x, y) <> 0x........ Then

WEnd

Else

Run( "cc.exe" )

EndFunc

Func d()

While Pixelgetcolor( x, y) <> 0x........Then

WEnd

Else

Run( "rdd.exe" )

EndIf

Func cal()

While Pixelgetcolor( x, y) <> 0x...........Then

WEnd

Else

Run( "cal.exe" )

EndIf

Thanks a bunch! sorry for my noobness :idea:

Edited by Ham123

Share this post


Link to post
Share on other sites



up!

Share this post


Link to post
Share on other sites

Please wait before bumping posts. Read my signature


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Please wait before bumping posts. Read my signature

sorry, wont happen again.

Share this post


Link to post
Share on other sites

Not sure I entirely comprehend what you're trying to do but from what I can gather this may help... (Dude change your fuction names etc. to something meaningful!)

While 1
    $PxlColour = pixelgetcolor( x, y)
    Switch $PxlColour
        Case 0x....
            DoSomething()
        Case 0x....
            DoSomethingElse()
    EndSwitch
Wend

You can use ExitLoop under a case to break the while loop :)

Matt

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Not sure I entirely comprehend what you're trying to do but from what I can gather this may help... (Dude change your fuction names etc. to something meaningful!)

While 1
    $PxlColour = pixelgetcolor( x, y)
    Switch $PxlColour
        Case 0x....
            DoSomething()
        Case 0x....
            DoSomethingElse()
    EndSwitch
Wend

You can use ExitLoop under a case to break the while loop :)

Matt

I guess my main question is how to to loop back to a certain function?

so

Case 0x....

Do something() ;this would loop back to the first function (bb)

Case 0x....

Dosomethingelse() ;this would loop back to the previous function (cal)

the func names are just acronyms.

Edited by Ham123

Share this post


Link to post
Share on other sites

bump! so now just trying to figure out a function that would loop back to the first function (bb) and another function which would loop back to the previous function (cal)

Share this post


Link to post
Share on other sites

bump! so now just trying to figure out a function that would loop back to the first function (bb) and another function which would loop back to the previous function (cal)

Please show the code that you now have with annotations of what you what to happen and where you would like for it to take place - like you did in your first post.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

code underlined is what im trying to figure out.

CODE

Func bb()

Run( "z.exe" )

EndFunc

other code here

Func cal()

While pixelgetcolor( x, y) <> 0x...... Then

Wend

Else

run( "cal.exe" )

Endfunc

Func return()

If pixelgetcolor( x, y) = 0x......... Then

(command to return to func bb?)

Else

(command to return to func cal?)

Endfunc

Edited by Ham123

Share this post


Link to post
Share on other sites

Func return()
If pixelgetcolor( x, y) = 0x......... Then
bb()
Else
cal()
Endfunc


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Func return()
If pixelgetcolor( x, y) = 0x......... Then
bb()
Else
cal()
Endfunc

oh lol, but will it actually loop back? or will it just execute that function?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

First - this is not valid code

While pixelgetcolor( x, y) <> 0x...... Then

Wend

Second - this is not valid code - missing an EndIf

Func return()

If pixelgetcolor( x, y) = 0x......... Then

(command to return to func bb?)

Else

(command to return to func cal?)

Endfunc

Third - your sample code does not show how/where/when you called the func named bb

Forth - naming a Func "Return" is not allowed as there is a built in func named "Return" and that is what you want to use to return to "bb".

Edit2: Technically, you can name the EDF "Return" - you just cannot call it.

Edit: post some working code or valid pseudo code because it matters where/how you call the bb function - to avoid recursion.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

First - this is not valid code

While pixelgetcolor( x, y) <> 0x...... Then

Wend

Second - this is not valid code - missing an EndIf

Func return()

If pixelgetcolor( x, y) = 0x......... Then

(command to return to func bb?)

Else

(command to return to func cal?)

Endfunc

Third - your sample code does not show how/where/when you called the func named bb

Forth - naming a Func "Return" is not allowed as there is a built in func named "Return" and that is what you want to use to return to "bb".

Edit: post some working code or valid pseudo code because it matters where/how you call the bb function - to avoid recursion.

The code you posted was typed up quickly, sorry i didnt make myself clear. i understand what i did wrong in them. I also know that return is not allowed as a function.

Basically this:

Func rtrn()

If pixelgetcolor( x, y) = 0x......... Then

(command to return to func bb?)

Else

(command to return to func cal?)

Endif

Endfunc

just want to know how to loop back is all.

EDIT: (sorry didnt see this)

as to the function BB its just a beginbutton. When the user presses a button then it automatically starts this function which runs z.exe

Edited by Ham123

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

bb()

Func rtrn()
    If PixelGetColor(1, 1) = 0x000000 Then
        ;(command To Return To Func bb?)
        Return
    Else
        ;(command To Return To Func cal?)
        Return
    EndIf
EndFunc   ;==>rtrn

Func bb()
    rtrn()
EndFunc   ;==>bb

Func cal()
    rtrn()
EndFunc   ;==>cal
Edit: I doubt that this will do what you want - it is more to show what I meant by saying that it matters where you call the bb func from. Knowing what you are attempting to accomplish with your code might help us to help you.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

... as to the function BB its just a beginbutton. ...

So we are talking part of your own GUI - right?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

bb()

Func rtrn()
    If PixelGetColor(1, 1) = 0x000000 Then
        ;(command To Return To Func bb?)
        Return
    Else
        ;(command To Return To Func cal?)
        Return
    EndIf
EndFunc   ;==>rtrn

Func bb()
    rtrn()
EndFunc   ;==>bb

Func cal()
    rtrn()
EndFunc   ;==>cal
Edit: I doubt that this will do what you want - it is more to show what I meant by saying that it matters where you call the bb func from. Knowing what you are attempting to accomplish with your code might help us to help you.
Ah its a very simple code :)

CODE

Func bb() ;beginbutton for users

Run( "z.exe") ;beings first part

endfunc

func ___() ;begins next function

While pixelgetcolor( x, y) <> 0x000000 ;performs pixel test, if not true, keeps doing it till is true.

Wend

Else ;if it is true, then runs

Run( ".exe") ;whichever exe

endfunc

func ___() ;begins next function

While pixelgetcolor( x, y) <> 0x000000 ;performs pixel test, if not true, keeps doing it till is true.

Wend

Else ;if it is true, then runs

Run( ".exe") ;whichever exe

endfunc

func cal() ;begins next function

While pixelgetcolor( x, y) <> 0x000000 ;performs pixel test, if not true, keeps doing it till is true.

Wend

Else ;if it is true, then runs

Run( "cal.exe") ;whichever exe

endfunc

func rtrn() ;loops back to function BB or function cal

If pixelgetcolor( x, y) = 0x000000 ;performs pixel test, if true goes to bb, else goes to cal

COMMAND to go to BB

else

COMMAND to go to CAL

Endif

Endfunc

So we are talking part of your own GUI - right?

Yup.

EDIT: so basically need to find out what those command would be. to loop back to bb or cal.

EDIT2: by loop back, i mean actually loop back. if it goes to bb it will execute the file, then continue on with the other functions till it hits func rtrn()

Edited by Ham123

Share this post


Link to post
Share on other sites

Where in your sample code do you call the func named rtrn()


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Where in your sample code do you call the func named rtrn()

After func cal has executed. func rtrn() is executed. func rtrn's pixelgetcolor is true, then it goes back to BB, else it goes to CAL.

sry if that didnt answer your question, i guess i dont exactly understand what you're asking.

Share this post


Link to post
Share on other sites

Just because you place a func in the script does not mean that it will run... you have to call it.

Please run this code from within the SciTE editor:

Func cal() ;begins next function
    MsgBox(0, "cal", "Did this msgbox appear?")
EndFunc   ;==>cal

Func rtrn() ;loops back to function BB or function cal
    MsgBox(0, "rtrn", "Did this msgbox appear?")
EndFunc   ;==>rtrnoÝ÷ Ù8^Ú-ëì"¶aÇ(u殶­sf6 §'G&â ¤gVæ26¶&Vvç2æWBgVæ7Föà¤×6t&÷ÂgV÷C¶6ÂgV÷C²ÂgV÷C´FBF2×6v&÷V#ògV÷C²¤VæDgVæ2³ÓÒfwC¶6À ¤gVæ2'G&â¶Æö÷2&6²FògVæ7Föâ$"÷"gVæ7Föâ6À¤×6t&÷ÂgV÷C·'G&âgV÷C²ÂgV÷C´FBF2×6v&÷V#ògV÷C²¤VæDgVæ2³ÓÒfwC·'G&à

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Just because you place a func in the script does not mean that it will run... you have to call it.

Please run this code from within the SciTE editor:

Func cal() ;begins next function
    MsgBox(0, "cal", "Did this msgbox appear?")
EndFunc   ;==>cal

Func rtrn() ;loops back to function BB or function cal
    MsgBox(0, "rtrn", "Did this msgbox appear?")
EndFunc   ;==>rtrnƒoÝŠ÷ Ù8^Ú-…ë™ì"¶aŠÇ(u殶ˆ­sf6‚ §'G&â‚ ¤gVæ26‚’¶&Vv–ç2æW‡BgVæ7F–öà¤×6t&÷‚ƒÂgV÷C¶6ÂgV÷C²ÂgV÷C´F–BF†—2×6v&÷‚V#ògV÷C²¤VæDgVæ2³ÓÒfwC¶6À ¤gVæ2'G&â‚’¶Æö÷2&6²FògVæ7F–öâ$"÷"gVæ7F–öâ6À¤×6t&÷‚ƒÂgV÷C·'G&âgV÷C²ÂgV÷C´F–BF†—2×6v&÷‚V#ògV÷C²¤VæDgVæ2³ÓÒfwC·'G&à

ah lol. ok so. basically then it would be

CODE

while 1

bb()

other func here()

other func here()

other func here()

cal()

If pixelgetcolor(x, y) = 0x000000 Then

wend

Else

cal()

Endif

Func bb ()

stuff here

endfunc

other funcs

func cal()

stuff here

end func

Am i correct in this?

it would go through

bb

other

other

other

cal

then pixel test, if true, goes to bb

else goes to cal. after cal will go through pixel test one more time to see if its true or not?

Edited by Ham123

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