|
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
|
05-01-2007 12:06
For the sake of easy editing my scripts I am separating into functions the component parts of an event handler such as link_message.
function1(integer num1, string str1) { //do something }
function2(integer num2, string str2) { //do something }
.....
link_message(integer sender_num, integer num, string str, key id) { if (sender_num == 1) { function1(num,str); function2(num.str); } }
....
are there any problems in using the parameters num instead of num1 and num2 or str instead of str1 and str2 if the values remain unchanged within the event handler?
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
05-01-2007 12:10
In short, no. Like most procedural languages, the names of formal parameters in a function have no required correlation to the names of actual parameters. They can be the same, or can be completely different. Only the types of the data that is passed have to match. That said, it is a wise programming practice to make the names correlated in such a way that makes sense to you (and others) as the programmer. 
|
|
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
|
05-01-2007 12:11
No that should work.
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
Pass by value
05-01-2007 13:24
LSL uses an approach called pass by value. In your case, think of it like this:
when you call f(num), it figures out the value of 'num' and then assigns it to 'num1'. You can actually change num1 all you want, and num won't change.
|