Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: spook1 on Sun 25/04/2004 21:28:52

Title: can a function return an array?
Post by: spook1 on Sun 25/04/2004 21:28:52
Simple question: can a function return an array?
And can I collect data from the function like

value.x = MyFunction(inputparamter).xcoordinate;
value.y = MyFunction(inputparamter).ycoordinate;
value.speed = MyFunction(inputparamter).speed;

or can I even state:

value= MyFunction(inputparameter);

Cheers,
Martijn
Title: Re:can a function return an array?
Post by: Robert Eric on Mon 26/04/2004 00:10:00
You seem to want to use classes in that first one.
Title: Re:can a function return an array?
Post by: stuh505 on Mon 26/04/2004 00:51:04
QuoteSimple question: can a function return an array?

Yes, a function can return an array.  I don't know if AGS allows this or not...why don't you try it and tell us

And can I collect data from the function like

Quote
value.x = MyFunction(inputparamter).xcoordinate;
value.y = MyFunction(inputparamter).ycoordinate;
value.speed = MyFunction(inputparamter).speed;

As Eric pointed out, this is the notation you would use to call a function that is within a class.

int x_value = MyClass.GetXCoordFunction(int parameter);

Quotevalue= MyFunction(inputparameter);

This is the regular way of using a function.
Title: Re:can a function return an array?
Post by: spook1 on Mon 26/04/2004 09:16:04
 am not sure about the classes. I use the struct command to set up value.x, value.y etc.

cheers,

martijn
Title: Re:can a function return an array?
Post by: Pumaman on Mon 26/04/2004 21:04:15
Functions cannot return structs or arrays - they can only return primitive types.

The workaround is to create a global variable which the function updates.