Sign in to follow this  
Followers 0
ileandros

Function get confused calling other funtions

24 posts in this topic

Hi there,

Let me show you an example of how my code is.

Func First()
While 1
;some staff here
Call("Test1")
Call("Test2")
Call("Test3")
;some other staff here
WEnd
EndFunc

Func Test1()
EndFunc

Func Test2()
EndFunc

Func Test3()
Call("First")
EndFunc

Ok so my code is something like this with a lot more functions calling each other(this was an example).

My problem is that when the function First() runs after it calls the 3 other functions normaly it should restart the First() functions, since the 3rd(Test3) one is calling it again, and keep doing this.

It restart but sometimes it get confused or i don't know what is going on here and the First() function doesnt seem to work normaly. It doesn't call again the 3 functions. It does the other staff that are included in the function but it doesnt re call the other 3 functions(Test1, Test2, Test3)

It is a little bit confusing even reading this post but give me a hand here. Haven't face this problem again.

Regards


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites



I wrote what I thought would happen if I ran your script. This is what I predicted:

First
    Test1
    Test2
    Test3
        Test1
        Test2
        Test3
            Test1
            Test2
            Test3

You run First() only once and then get into a loop of the other 3 functions. I used msgboxes to illustrate it. Here's what I did to prove it.

First()

Func First()
While 1
;some staff here
MsgBox(0, "", "Func 0")
Call("Test1")
Call("Test2")
Call("Test3")
;some other staff here
WEnd
EndFunc

Func Test1()
MsgBox(0, "", "Func 1")
EndFunc

Func Test2()
MsgBox(0, "", "Func 2")
EndFunc

Func Test3()
MsgBox(0, "", "Func 3")
Call("First")
EndFunc

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The while loop never completes because it can't continue beyond the function Test3(). Test3() only repeats the first part of the loop because it is called over and over before the loop in First() has finished.

Edited by czardas

Share this post


Link to post
Share on other sites

The while loop never completes because it can't continue beyond the function Test3(). Test3() only repeats the first part of the loop because it is called over and over before the loop in First() has finished.

Yeah this is a point but how should i change it to make the First() function complete. And besides that since Test3() is calling First() then the loop should run again and again until the Call("Test3()") and then start over again. My problem is why it gets confused and sometimes it doesnt call some funtions that are called before Test3()???

I wrote what I thought would happen if I ran your script. This is what I predicted:

First
Test1
Test2
Test3
Test1
Test2
Test3
Test1
Test2
Test3

You run First() only once and then get into a loop of the other 3 functions. I used msgboxes to illustrate it. Here's what I did to prove it.

First()

Func First()
While 1
;some staff here
MsgBox(0, "", "Func 0")
Call("Test1")
Call("Test2")
Call("Test3")
;some other staff here
WEnd
EndFunc

Func Test1()
MsgBox(0, "", "Func 1")
EndFunc

Func Test2()
MsgBox(0, "", "Func 2")
EndFunc

Func Test3()
MsgBox(0, "", "Func 3")
Call("First")
EndFunc

I am not sure if u understood what i said...

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

First, and the most important, don't recurse your function call like that, anything after the Call("Test3") line is never ever going to get actioned on.

Second, there's absolutely no reason why it wouldn't run the 3 functions every time First is started, your code should endlessly loop through the functions.

Third, this script will crash because of the way you have it recursing back to the first function, figure out another way of running this.

Fourth, there's no reason to use the command Call to jump to a function unless your function call is using a string that changes such as "Test" & $I, save yourself the typing.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

First, and the most important, don't recurse your function call like that, anything after the Call("Test3") line is never ever going to get actioned on.

I know thats why i am using it. Call("Test3") checks for something and if it is true it takes action. I used Call("First") at the end of Test3() because i dont want anything after the Call("Test3") to get actioned on if the check is true.

Second, there's absolutely no reason why it wouldn't run the 3 functions every time First is started, your code should endlessly loop through the functions.

Answer is the same as above

Third, this script will crash because of the way you have it recursing back to the first function, figure out another way of running this.

I tried a lot of ways thats why im posting here :/ Is there an other way of doing this ?

Fourth, there's no reason to use the command Call to jump to a function unless your function call is using a string that changes such as "Test" & $I, save yourself the typing.

Maybe here ur right because i read a lot of people saying the same thing. Would this change something in the script?

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Since when did we start jumping functions instead of using loops to perform repeating actions? :thumbsdown:

Func First()
  While 1
    ;some staff here
    Test1()
    Test2()
    If Not Test3() Then ContinueLoop
  ;some other staff here
  WEnd
EndFunc

    Func Test1()
    EndFunc

        Func Test2()
        EndFunc

            Func Test3()
              If Not $whatever Then Return False
            EndFunc
Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Your posted code is useless to help us figure out what is going wrong in your script. This posted code obviously has no connection with what you're really doing in the script because there are no conditional checks being done, you're just jumping from one function to another and then recursing to the first one again. If you want real help, post the code that's not working, not something that isn't going to help you, or help us help you. If you're unwilling to post even a reproducer script that shows what you're doing in your real script then you're on your own.

As stated, this code will run all three of your functions every time, then jump back to the First() function and do it all over again. So, to answer your original question, there's nothing wrong with your code, must be something else you're not showing us.

Once you figure out how to post the code that isn't working, come back for some real help. In the meantime, stop asking pointless questions and posting shit code.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

ileandros, Can't you do it like this:

Func First( $level )
If $level = 0 Then Return
Test1()
Test2()
Test3( $level )
EndFunc

Func Test1()
ConsoleWrite( "Test1" & @LF )
EndFunc

Func Test2()
ConsoleWrite( "Test2" & @LF )
EndFunc

Func Test3( $level )
ConsoleWrite( "Test3 " & $level & @LF )
First( $level - 1 )
EndFunc

First( 2000 )

First( 5000 ) will give an error.

Share this post


Link to post
Share on other sites

Since when did we start jumping functions instead of using loops to perform repeating actions? :thumbsdown:

Func First()
While 1
;some staff here
Test1()
Test2()
If Not Test3() Then ContinueLoop
;some other staff here
WEnd
EndFunc

Func Test1()
EndFunc

Func Test2()
EndFunc

Func Test3()
If Not $whatever Then Return False
EndFunc

This is no much different from my script. It will get confused and not call all functions sometimes.

Your posted code is useless to help us figure out what is going wrong in your script. This posted code obviously has no connection with what you're really doing in the script because there are no conditional checks being done, you're just jumping from one function to another and then recursing to the first one again. If you want real help, post the code that's not working, not something that isn't going to help you, or help us help you. If you're unwilling to post even a reproducer script that shows what you're doing in your real script then you're on your own.

As stated, this code will run all three of your functions every time, then jump back to the First() function and do it all over again. So, to answer your original question, there's nothing wrong with your code, must be something else you're not showing us.

Once you figure out how to post the code that isn't working, come back for some real help. In the meantime, stop asking pointless questions and posting shit code.

Did i ever said my script is not working???

It restart but sometimes it get confused or i don't know what is going on here and the First() function doesnt seem to work normaly. It doesn't call again the 3 functions. It does the other staff that are included in the function but it doesnt re call the other 3 functions(Test1, Test2, Test3)

And this is the best reproducer i can build. Making it better would only add coding script in the functions nothing else. I wrote this because i know that something is wrong with the calling functions

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

This is no much different from my script. It will get confused and not call all functions sometimes.

Did i ever said my script is not working???

Yes, you said your script wasn't working you even QUOTED where you said it wasn't working, right after you asked this question. You even repeated that it wasn't working in this post, just before you asked where you said it didn't work.

And this is the best reproducer i can build. Making it better would only add coding script in the functions nothing else. I wrote this because i know that something is wrong with the calling functions

Make it better, because what you posted works fine.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

This is no much different from my script. It will get confused and not call all functions sometimes.

...

Perform functions 1, 2 and 3... if something doesn't check out correctly in function 3, return false. If function 3 returns false, restart the damn loop.

How the hell is it "not call all functions sometimes.". If your code is written correctly, it should do exactly what is stated above. If it's not performing correctly, the problem lies in some code in the functions not performing correctly.

1 person likes this

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

ileandros,

If you are trying to find a way to create calls to dynamic function names this may help. The following code calls functions based on randomly generated function names.

;
;
;

f010("main")

func f010($caller)
 consolewrite("f010 called by " & $caller & @lf)
 local $next = random(1,3,1)
 consolewrite("   Next call will be to function f0" & $next & "0" & @lf)
 sleep(2000)
    execute("f0" & $next & "0(" & "'f010')")
EndFunc
func f020($caller)
 consolewrite("f020 called by " & $caller & @lf)
 local $next = random(1,3,1)
 consolewrite("   Next call will be to function f0" & $next & "0" & @lf)
 sleep(2000)
    execute("f0" & $next & "0(" & "'f020')")
EndFunc
func f030($caller)
 consolewrite("f030 called by " & $caller & @lf)
 local $next = random(1,3,1)
 consolewrite("   Next call will be to function f0" & $next & "0" & @lf)
 sleep(2000)
    execute("f0" & $next & "0(" & "'f030')")
EndFunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Well guys because i couldnt get the controlID of some items in my programm i used ImageSearch and pixelsearch. I found out that they were confusing my script and it wasnt working correclty.

But i got a question.

Func First()
While 1
;some staff here
Test1()
;some other staff here
Test3()
WEnd
EndFunc

Func Test1()
If $Whatever Then
Test2()
EndFunc

Func Test2()
First()
EndFunc

Func Test3()
EndFunc

First() does some staffs, calls Test1() , doest some other staffs after and then calls Test3()

Test1() checks and calls Test2()

What i want to do is, if Test2() gets action then restart the entrire loop from the beggining. Is it correct like this?

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

What i want to do is, if Test2() gets action then restart the entrire loop from the beggining. Is it correct like this?

Here's a suggestion, TRY it :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Maybe something like below.

Make Test2() return an exit code so we know if it got action.

Dont let the loop end until conditions for exitloop are met.

Func First() While 1
;some staff here
Test1()
;some other staff here
Test3()
WEnd
EndFunc
Func Test1()
While 1
  If $Whatever Then
   If Not Test2() Then ExitLoop ;If gets action restart at top
  EndIf     ;If no action return to evaluate $whatever
WEnd
EndFunc
Func Test2()
First()
Return $ExitCode ; **** Return an exit code 1 = 'got some action', 0 = 'no action'
EndFunc
Func Test3()
EndFunc

Share this post


Link to post
Share on other sites

What i want to do is, if Test2() gets action then restart the entrire loop from the beggining. Is it correct like this?

Sure, if you by "correct" mean crashing AutoIt. You were told in post #5, no endless recursion! Simply loop the part you want to repeat instead.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

*sigh*...

Func First()
  While 1
    Sleep(10) ; Just in case...
    ;some staff here
    If Not Test1() Then ContinueLoop ; Trigger target from Test2(). Restart the while loop.
    ;some other staff here
    Test3()
  WEnd
EndFunc

Func Test1()
  If $Whatever Then
    If Not Test2() Then Return False ; Continuing the trigger in Test2()
  EndIf
EndFunc

Func Test2()
  Return False ; Trigger the while loop in First() to restart
EndFunc

Func Test3()
EndFunc
Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Sure, if you by "correct" mean crashing AutoIt. You were told in post #5, no endless recursion! Simply loop the part you want to repeat instead.

The part i want to repeat is the entire code. The only problem in this script was that it was crashing. Meaning not closing the script but confusing it.

The entire code has some commands and calls some other functions by time to check.

Changin "Call(Test1)" ,which i was using for the funtions, in Test1() etc gave the solution since i had no strings as BrewManNH said.

Tried 3 days in row for 8 hours of working and it was and still is working like a charm.

Regards


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

Well guys because i couldnt get the controlID of some items in my programm i used ImageSearch and pixelsearch. I found out that they were confusing my script and it wasnt working correclty.

If you want help fixing broken code, the reproducer needs to also be broken. If it ain't broke we can perhaps improve it but we can't fix it. It is also impossible to change its behaviour without knowing what it is meant to do. I have been following this topic for three days now and I still don't have a clue what you are trying to achieve with these functions. I'm wondering if you have thought this out clearly enough.

You have three functions. Which one isn't working? Why isn't it working? Does the problem remain when you remove the other functions? Have you tried to rewrite the broken function differently? You are automating something. Where are the error checks? Do the error checks cover all scenarios? Functions generally only work properly when they are written correctly.

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