Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: suicidal pencil on Tue 02/12/2008 01:42:57

Title: Function within a function and recursion
Post by: suicidal pencil on Tue 02/12/2008 01:42:57
Two part question, all about functions.

part A) Can you have a recursive function (Have the function call itself)?

and

part B) Can you have a function call another function? (having 'function DoThis()' use 'function DoThat()', then continue on)?

Title: Re: Function within a function and recursion
Post by: RickJ on Tue 02/12/2008 03:33:22
A) I believe so but care must be taken with the stack.  Perhaps some others here have something more specific.

B) Yes definitely!.
Title: Re: Function within a function and recursion
Post by: Khris on Tue 02/12/2008 09:01:24
Yes, recursive functions are possible.

I'm curious, why didn't you just try it...?
Title: Re: Function within a function and recursion
Post by: suicidal pencil on Tue 02/12/2008 12:07:44
I still don't know the full extent of what the scripting language can do, and I didn't think that it could.

Thanks for the answer. Knowing that I can do it will make life sooooo much easier for me.
Title: Re: Function within a function and recursion
Post by: Pumaman on Tue 02/12/2008 18:18:43
Yes, however the script engine will not allow a call stack more than 50 functions deep, so if you wanted to do some kind of recursive sort requiring hundreds of nested function calls you would not be able to do so at present.