Sign in to follow this  
Followers 0
JuniorCoder

Changing Func Name? Goto? Recursive?

11 posts in this topic

#1 ·  Posted (edited)

Two questions;

This is a noob question but I'm learning and therefore not embarrassed to ask so is there any way to declare the name of a Function on the draw?  For instance if I wanted to change a variable from 1 to 2 every time a func is called and use the variable as the new func name?

Func _Change_Func_Name()
    
if $var=1 then
$var+=1
Else
$var-=1
EndIf
$New_Func_Name=_Search_Bar&$frac&()

EndFunc



Func $New_Func_Name()


Endfunc

Obviously this wont work I used it as a example of what I wanted to do but is there anything I can do similar to the affect.

 

 

And noob question two, if I call a func within a previously running func before the previously running func has ended it calls a recursive func is there any way after the new func is called to exit out of the previous recursive func?  In one of my current projects recursive func as goto is necessary and after about 4 hours of running it gets a recursive amount exceeded error.

 

I wish I had a func that could  jump into a new func and then would exit out of the previous running and not yet finished func. Shouldn't there be a Goto func for this?

Edited by JuniorCoder

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Your code example is not really explaining more that your description does not.

Please show an example of what your "current project" is doing, to better explain what exactly you are asking.

Ok John

_check_Folders()

Func _check_Folders()
    
While 1

_check()
    
WEnd

EndFunc

Func _check()

if $check="Fail" then
_check_Folders(); just called a new func without exiting old func  used as Goto
EndIf

EndFunc

This is an example of a Recursive Func when _check_Folders() is called before its ended.  Now I know a simple while loop can fix this example but, my project is not as simple being there is like 2k lines of code and a lot of other functions in order and steps needing to take place before the func gets called.  In saying that my current project does need to use recursive functions and my question again is there a func that could jump into a new func and then would exit out of the previous running and not yet finished func? Its called Goto but since it was removed from Autoit, you can only call a function inside a already running function and this can only achieved a certain amount of times depending on your computers memory before Autoit will close from exceeding its recursive limit. So what do you do instead of Goto?

Edited by JuniorCoder

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

No.

There is no goto, and nothing that emulates it in the manner you describe.

 WOW how sad that means the amount of times you can call functions inside already running functions depends on the amount of memory on the persons pc . So how then can you clear the old running Function after the new function is called?

Edited by JuniorCoder

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

What language are you coming from?

Here's an example of how I'd code something similar to what you appear to want.

While 3
    ConsoleWrite("Main loop" & @LF)
    If Func1() Then
        Exit
    EndIf
    Sleep(500)
WEnd

Func Func1()
    ConsoleWrite("Func1" & @LF)
    While 3
        If Not Func2() Then
            ConsoleWrite("Out" & @LF)
            Return True
        EndIf
        ConsoleWrite("In" & @LF)
    WEnd
EndFunc   ;==>Func1

Func Func2()
    ConsoleWrite("Func2" & @LF)
    Static $var = 0
    If $var > 2 Then
        $var = 0
        Return False
    EndIf
    ConsoleWrite($var & @LF)
    $var += 1
    Return True
EndFunc   ;==>Func2
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

 

What language are you coming from?

Here's an example of how I'd code something similar to what you appear to want.

While 3
    ConsoleWrite("Main loop" & @LF)
    If Func1() Then
        Exit
    EndIf
    Sleep(500)
WEnd

Func Func1()
    ConsoleWrite("Func1" & @LF)
    While 3
        If Not Func2() Then
            ConsoleWrite("Out" & @LF)
            Return True
        EndIf
        ConsoleWrite("In" & @LF)
    WEnd
EndFunc   ;==>Func1

Func Func2()
    ConsoleWrite("Func2" & @LF)
    Static $var = 0
    If $var > 2 Then
        $var = 0
        Return False
    EndIf
    ConsoleWrite($var & @LF)
    $var += 1
    Return True
EndFunc   ;==>Func2

 

Its Ok John thank you for your replies, I see by your example you still dont fully understand what I'm talking about here is a few links i just found that other people had the same discussion about.

https://www.autoitscript.com/wiki/Recursion

'?do=embed' frameborder='0' data-embedContent>>

'?do=embed' frameborder='0' data-embedContent>>

But I still cant find a definitive solution to my problem.

In one of my current projects recursive functions are necessary and after about 4 hours of running it gets a recursive amount exceeded error.

I'm probably gonna have to try a counter and automatic reboot for the whole .exe if I have to.

Share this post


Link to post
Share on other sites

I'm sure whatever it is that you're doing can be done without recursion, or at least a minimal amount of recursion. Perhaps if you posted your script, or a good reproducer that shows what it is you're trying to achieve, we can be of some help. I don't think rebooting is going to be the answer if you want a good answer.


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

JuniorCoder,

This may be of some interest to you...

; recursive

local $str = '123456789'

ConsoleWrite('Recursive method' & @CRLF)

_display_recurse($str)

func _display_recurse($s)
    local static $idx = 1
    ConsoleWrite(stringmid($s,$idx,1) & @CRLF)
    $idx += 1
    if $idx <= stringlen($s) then _display_recurse($s)
endfunc

; non - recursive

ConsoleWrite('Non-recursive method' & @CRLF)

while _display_nonrecurse($str)
wend

func _display_nonrecurse($s)
    local static $idx = 1
    ConsoleWrite(stringmid($s,$idx,1) & @CRLF)
    $idx += 1
    if $idx <= stringlen($s) then return true
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

#11 ·  Posted (edited)

JuniorCoder,

This may be of some interest to you...

; recursive

local $str = '123456789'

ConsoleWrite('Recursive method' & @CRLF)

_display_recurse($str)

func _display_recurse($s)
    local static $idx = 1
    ConsoleWrite(stringmid($s,$idx,1) & @CRLF)
    $idx += 1
    if $idx <= stringlen($s) then _display_recurse($s)
endfunc

; non - recursive

ConsoleWrite('Non-recursive method' & @CRLF)

while _display_nonrecurse($str)
wend

func _display_nonrecurse($s)
    local static $idx = 1
    ConsoleWrite(stringmid($s,$idx,1) & @CRLF)
    $idx += 1
    if $idx <= stringlen($s) then return true
endfunc

kylomas

Coool I haven't tried it yet but with this it looks like I can use it for keeping count of the recursive functions. Thank you

Edited by JuniorCoder

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