Konan--M 0 Posted September 28, 2004 Is it possible that a function calls itself with other parameters and if the new called funktion ends, that the old one's going on ???? I don't care about the limiter of 384 reg levels, just want to know if its possible? Share this post Link to post Share on other sites
SlimShady 1 Posted September 28, 2004 Is it possible that a function calls itself with other parameters and if the new called funktion ends, that the old one's going on ???? I don't care about the limiter of 384 reg levels, just want to know if its possible? <{POST_SNAPBACK}>Possible. Personally I think it's stupid. I made many scripts and I've always found a way to avoid this. Here's what silly people would do: RunThis("C:\WINNT\notepad.exe", "C:\WINNT\WindowsUpdate.log") Func RunThis($par1, $par2) Local $Filename Local $Args $Filename = $par1 $Args = $par2 If NOT FileExists($Filename) Then $Filename = StringReplace($Filename, "C:\", "D:\") RunThis($Filename, $Args) Else Run($Filename & " " & $Args) EndIf EndFunc Here's what I would do: RunThis("C:\WINNT\notepad.exe", "C:\WINNT\WindowsUpdate.log") If @error Then RunThis("D:\WINNT\notepad.exe", "D:\WINNT\WindowsUpdate.log") EndIf Func RunThis($par1, $par2) Local $Filename Local $Args $Filename = $par1 $Args = $par2 If NOT FileExists($Filename) Then SetError(1) Return Else Run($Filename & " " & $Args) EndIf EndFunc Share this post Link to post Share on other sites
Jon 1,009 Posted September 28, 2004 (edited) Possible.Personally I think it's stupid.I made many scripts and I've always found a way to avoid this.I used to think it was silly when I heard about it too, but most of AutoIt's internals are based on the fact that functions call themselves. Everytime you run a function AutoIt actually reruns it's main procedure.Try and write a program that gives you a list of every file on a disk without recursion - pretty much impossible Edited September 28, 2004 by Jon Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Share this post Link to post Share on other sites
Konan--M 0 Posted September 28, 2004 I used to think it was silly when I heard about it too, but most of AutoIt's internals are based on the fact that functions call themselves. Everytime you run a function AutoIt actually reruns it's main procedure. Try and write a program that gives you a list of every file on a disk without recursion - pretty much impossible <{POST_SNAPBACK}>I wasn't sure, because in my first scripts i tried recursion´, but it didn't work. And now i really need it and i wanted to be sure Share this post Link to post Share on other sites
Valik 478 Posted September 28, 2004 (edited) I used to think it was silly when I heard about it too, but most of AutoIt's internals are based on the fact that functions call themselves. Everytime you run a function AutoIt actually reruns it's main procedure. Try and write a program that gives you a list of every file on a disk without recursion - pretty much impossible <{POST_SNAPBACK}>What language? AutoIt? Very hard. C++, probably not all that hard if you used a linked-list that not only had siblings but children as well. class NodeDir { public: std::string name; NodeDir *pNextSibling; NodeDir *pPrevSibling; NodeDir *pParent; std::vector<NodeDir*> pChild; }; Then use a stack to track which node should be the root, pushing a new "root" on each time you go into a sub-directory. Once you hit bottom, pop the last item, look to see if there is another child in the new "root" (Sibling to the "root" just popped). Keep this up until everything is popped off the stack signifying you've fully traversed the directory structure of the drive. This would trigger an exit from the end of the while loop. Edit: Changed pChild to be a vector of pointers since it'd be necessary to have access to all children from the parent. Edited September 28, 2004 by Valik Share this post Link to post Share on other sites