fonction in a fonction ?

Discuss any general programming issues here
Post Reply
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

fonction in a fonction ?

Post 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
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: fonction in a fonction ?

Post 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?
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: fonction in a fonction ?

Post by djrikki »

Unless he means a recursive function which is also possible.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: fonction in a fonction ?

Post 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
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: fonction in a fonction ?

Post 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?
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: fonction in a fonction ?

Post 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
Mazze
Posts: 69
Joined: Thu May 06, 2010 8:08 pm

Re: fonction in a fonction ?

Post by Mazze »

Your English is hard to understand. Functions are called from within other functions.
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: fonction in a fonction ?

Post 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
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: fonction in a fonction ?

Post 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 :)
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: fonction in a fonction ?

Post 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
Post Reply