make a final fonction ?

Find quick help here to get you started with Hollywood
Post Reply
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

make a final fonction ?

Post 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
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: make a final fonction ?

Post by stefff285 »

ooops not in the main fonction but the include in the main script ?

regards
Bugala
Posts: 1391
Joined: Sun Feb 14, 2010 7:11 pm

Re: make a final fonction ?

Post 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()
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: make a final fonction ?

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