• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Discussion Is there a use case for makeref()?

Kahenraz

Landlubber
I see makeref() used throughout various scripts but I don't see a valid use case for it and haven't been able to come up with a reason for its existence. I suspect that it may be an artifact of an earlier version of the scripting language before the '&' operator became available.

Here is an example using makeref() to create a reference to a variable 'num' as 'rNum'. It can be demonstrated than 'rNum' references 'num':

Code:
string num = 123;

ref rNum;  makeref(rNum, num)
rNum = 456;

trace(num); // Outputs 456

This function isn't necessary since the '&' operator can already be used to assign a reference:

Code:
string num = 123;

ref rNum = #
rNum = 456;

trace(num); // Outputs 456

There are no problems working with arrays either:

Code:
int list[2];

list[0] = 123;
ref rNum = &list[0];
rNum = 456;

trace(list[0]); // Outputs 456

Is there an actual use case for makeref() or is it considered a deprecated feature?
 
I think using the & and makeref should yield the same result. But I'm not sure about the performance. Haven't ever checked to see which one works better. The original code also uses makeref so I guess others used that because that's what the original designers used a lot. I'm also not enterily sure if the scope of the ref is the same when using makeref or &, that's something you could try.
The makearef (I believe it was called that) function might still be needed if you want to create a reference to an attribute of an object. I believe from what I remember the & operator wont accept that very well.
 
Back
Top