Page 1 of 1

fonction in a fonction ?

Posted: Wed Jan 02, 2013 7:47 pm
by stefff285
hi all

i go to be back scripting under hollywood with sprites and fonctions

my question is : is it possible to make fonction in fonction ?

i mean without any inconenience with rapidity of compiled programm
under os 4 and morphos 3.1 and aros ?

regards to all , thanx by advance and happy new year to all

yogib33r^vitalmotion/x-men

Re: fonction in a fonction ?

Posted: Thu Jan 03, 2013 12:37 pm
by Allanon
Hello steff, why do you need to declare nested functions? Or you just want to call functions from inside other functions?

Example:

Code: Select all

Function mystuff2()
   ...
EndFunction
Function mystuff1()
   ...
   mystuff2()
EndFunction
As you see mystuff1() calls mystuff2(), is what you are trying to ask?

Re: fonction in a fonction ?

Posted: Thu Jan 03, 2013 6:10 pm
by djrikki
Unless he means a recursive function which is also possible.

Re: fonction in a fonction ?

Posted: Thu Jan 03, 2013 10:47 pm
by stefff285
hello gentlemen !

yes i would like to execute a fonction inside another to be executed before

then my question is : is it possible ? and then is it good for pegasos 1
for example as now i sold mine

regards to you

steff

Re: fonction in a fonction ?

Posted: Mon Jan 07, 2013 12:14 am
by Allanon
Sorry Steff, but I'm not able to get the point, can you try to explain with a little example what are you trying to do?

Re: fonction in a fonction ?

Posted: Tue Jan 08, 2013 10:15 am
by stefff285
hello allanon thanx for reply

the fact is that i did begun fonctions yesterday
and well seemed to understand that the main fonction
can have on itselft other fonctions declared before

in fact my questions was : is it possible to declare
a fonction inside another one ? or as i believe to declare
the first one and after make a main fonction to call it
in ?

i have to try to see and then test sprite more deeper

thanx a lot

steff

Re: fonction in a fonction ?

Posted: Tue Jan 08, 2013 8:23 pm
by Mazze
Your English is hard to understand. Functions are called from within other functions.

Re: fonction in a fonction ?

Posted: Tue Jan 08, 2013 10:20 pm
by stefff285
hello mazze

yes my english is a pity !!

but you answered to me :)

i have now the way to test fonctions

thanx a lot yet

stephane

Re: fonction in a fonction ?

Posted: Wed Jan 09, 2013 11:57 pm
by Allanon
Hi steff,
generally a program is divided in two parts, a declaration part (usually in the beginning) followed by a sequence of operations like functions call or a single function call that do all your stuff.

EXAMPLE

Code: Select all

; Function declaration
Function my_func1()
   ; your stuff
EndFunction

Function my_func2()
   ; your stuff
EndFunction

; Execute your stuff
my_func1()
my_func2()
...or, using a main function:

Code: Select all

; Function declaration
Function my_func1()
   ; your stuff
EndFunction

Function my_func2()
   ; your stuff
EndFunction

Function main()
   my_func1()
   my_func2()
EndFunction

; Execute your stuff
main()
As you can see main() function call my_func1() and my_func2(), that's it, a function call inside another function as Mazze as stated, functions call can be nested where the only limit is your free memory, have a look at the "Functions" chapter in the Hollywood guide, you will find many interesting things like recursive function calls.

Hope this helps :)

Re: fonction in a fonction ?

Posted: Thu Jan 10, 2013 10:35 pm
by stefff285
hello my dear allanon

yes it is exactly what i wanted to know

then well no enought time to script theses days but be sure
your answer won't be lost for me

thanx yet and regards

steff