Page 1 of 1

make a final fonction ?

Posted: Thu Mar 26, 2015 3:57 pm
by stefff285
hi all

harrr ! due to help of allanon and andreas and bulaga, soon my first good program (humhum i joke!) will be at a party in two months
actually i have various parts with main fonctions ()

so my idea is to include all this in a main fonction (while renaming others as p_1(), p_2()
are there some rules to respect for ? and have i to include all datas in the main one ?

thanx a lot by advance

regards

Re: make a final fonction ?

Posted: Thu Mar 26, 2015 5:19 pm
by stefff285
ooops not in the main fonction but the include in the main script ?

regards

Re: make a final fonction ?

Posted: Thu Mar 26, 2015 11:21 pm
by Bugala
When you use #INCLUDE. it in practice works same as using copy-paste.

So although part of your code is in different file, you could think it as:

Code: Select all

#INCLUDE file1
#INCLUDE file 2
rest of the code
being same as

Code: Select all

code from file 1
code from file 2
rest of the code

What comes to your function naming thing, you might have some use from emulating so called "method" approach.

Many c-type languages contain this thing called method. While Hollywood (And LUA, which Hollywood is derivative of) doesnt actually officially have Methods, they can easily be emulated however.

I am mentioning this name "method" just so that you can possib ly google more about it if you want, but I am giving you example what you could do which in practice is method.

AS you should know nby now, Hollywood can have "tables", as example mytable = {1, 2, 3}. But these tables are not restricted to just numbers, but they can also contain strings, even other tables AND... Functions.

Hence we could have for example:

Code: Select all

Dog = {}
dog.talk = FUNCTION  debugprint("wuf!") ENDFUNCTION
dog.sleep = FUNCTION debugprint("zzz...") ENDFUNCTION

dog.talk
dog.sleep
result:

Code: Select all

wuf!
zzz...

hence, instead of using function naming of p_1, p_2, you could just have p.1, p.2, maybe even p.1.1 if that p_1 has several functions.

And instead of declaring functions the way i did in example, it could also be done:

Code: Select all

function myhelloworldfunction()
debugprint("hello world")
endfunction

dog = {}
dog.talk = myhelloworldfunction()

Re: make a final fonction ?

Posted: Sat Mar 28, 2015 10:29 am
by stefff285
thank you so much bugala ^^ by the way i didn't forgot to tnak you so much on the scrolling texte :)
i go code now, with you cool help and the one of allanon

you rocks !

stéphane