Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: deltamatrix on Sun 16/10/2011 11:42:20

Title: Pass-by-reference?
Post by: deltamatrix on Sun 16/10/2011 11:42:20
Hi,

Sorry if this has already been asked but does AGS support pass-by-reference for primitives? I have some code that would look far cleaner and more concise if any form of pass-by-reference was supported.

Thanks

Delta
Title: Re: Pass-by-reference?
Post by: Calin Leafshade on Sun 16/10/2011 12:20:58
nope, fraid not.

you can only pass built in objects (Character, GUI, etc)  by reference.
Title: Re: Pass-by-reference?
Post by: deltamatrix on Sun 16/10/2011 12:51:34
dang. I hope the open-source devs do consider it. This means I gotta bulk up the src with repeated code.
Title: Re: Pass-by-reference?
Post by: Denzil Quixode on Sun 16/10/2011 17:23:09
Closest thing I could think of: you could try "boxing" values by placing them in a 1-length dynamic array and passing that:
function change(int thing[])
{
  thing[0] = 20;
}

function test()
{
  int thing[] = new int[1];
  thing[0] = 10;
  change(thing);
  Display("%d", thing[0]);
}