byref keyword

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
User avatar
andenixa
Grandmaster Poster
Posts: 105
Joined: Tue Nov 09, 2010 1:33 am

byref keyword

Post 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.
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am
Location: Italy

Re: byref keyword

Post 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 .
User avatar
andenixa
Grandmaster Poster
Posts: 105
Joined: Tue Nov 09, 2010 1:33 am

Re: byref keyword

Post 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.
kevin
POL Developer
Posts: 53
Joined: Wed Sep 29, 2010 3:47 pm
Contact:

Re: byref keyword

Post 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.
User avatar
andenixa
Grandmaster Poster
Posts: 105
Joined: Tue Nov 09, 2010 1:33 am

Re: byref keyword

Post by andenixa »

Quite so, thank you.
Post Reply