Page 1 of 1
byref keyword
Posted: Thu Aug 25, 2011 7:24 pm
by andenixa
I constantly see the extensive use of byref keywords in my shard's scripts.
Such as:
Code: Select all
function undress(byref character)
// code
endfunction
Does it have meaning for datatypes other than
int,
string,
list, and
dict?
Thank you.
Re: byref keyword
Posted: Fri Aug 26, 2011 1:49 am
by xeon
Hi andenixa, how're you?
Yes, byref implies that in your function you aren't handling a "copy" of the variable/object passed, but directly the variable/object .
Re: byref keyword
Posted: Fri Aug 26, 2011 4:33 pm
by andenixa
Hello,
I am fine.
How are you Xeon?
What I thought that *byrefing* variables which point to object references, such as characters and items, is useless, yet I see this every now and then. I was hopping Austin would shed some light on the regard.
Thank you for your help.
Re: byref keyword
Posted: Fri Aug 26, 2011 5:43 pm
by kevin
it is not useless for object references.
Code: Select all
program script(attacker,defender)
print("A: "+attacker+" D: "+defender);
swap(attacker,defender);
print("A: "+attacker+" D: "+defender); // Variables are swapped.
endprogram
function swap(byreference a, byreference b)
var temp = a;
a = b;
b = temp;
endfunction
byreference is useful if you want to modify the
contents of the variable and have that modification be visible to the calling function. hope that clears it up.
Re: byref keyword
Posted: Sat Aug 27, 2011 11:28 am
by andenixa
Quite so, thank you.