Page 1 of 1

How to have chaging amount of variables in function call?

Posted: Sun Aug 01, 2010 5:57 pm
by Bugala
Since some of Hollywoods own functions work this way, there must be a way for user to do the same.

So thing is, I would want to make a function, that could in different places of code receive different amount of variables to it.


As example.

first it would use:

Code: Select all

P_talkbox(x, y, $message)
then later in the code there could be same function call but with more arguments in way of:

Code: Select all

P_talkbox(x, y, $message, $color, $colorofbox, amountoftransparency)

Therefore how can i then do it so that:

Code: Select all

Function p_talkbox(x , y, $message, $color, $colorofbox, amountoftransparency)

IF there is $color
   $color=$color
ELSE
   $color=777777
ENDIF

IF there is amontoftransparency
   amountoftrasnparency=amountoftransparency
ELSE
   amoungoftrasnparency=255
ENDIF


P_Drawtalkbox(x, y, $message, $color, $colorofbox, amountoftransparency)


ENDFUNCTION

Re: How to have chaging amount of variables in function call?

Posted: Sun Aug 01, 2010 7:06 pm
by jalih
There is a good example in documentation.

In your case it would be something like: Function p_talkbox(x , y, message$, ...)

- Your function now holds a local table called arg
- arg.n holds the number of arguments function received.
- arguments, that function received are stored in the arg table starting at index 0, thus the first function argument is stored at arg[0].

Re: How to have chaging amount of variables in function call?

Posted: Mon Aug 02, 2010 3:42 am
by Bugala
Ah, so its very much like perl then.

Thanks a lot again Jalih, i can proapbly figure the rest myself from this already.