How to have chaging amount of variables in function call?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

How to have chaging amount of variables in function call?

Post 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
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

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

Post 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].
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

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

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