Function return custom type

Started by Grew, August 07, 2014, 07:54:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Grew

Hi,
Is there a way to make a function return a custom type ?

For example :

type point
   int x, y;
end

type rect
   int x0, x1, y0, y1;
end

function rect return_rect(point p1, point p2)
private
   rect return_rect;
begin
   return_rect.x0 = p1.x;
   return_rect.y0 = p1.y;
   return_rect.x1 = p2.x;
   return_rect.y1 = p2.y;
   
   return return_rect;
end


This code give me this error :
Quoteerror: Struct required ( token error: ")" ).

Any idea ?


(I doubt this is possible.)
My game developer instagram :
https://www.instagram.com/ben_dev_game/

handsource-dyko

Maybe if you use declare? It works on strings. In your case, you could do a work around by creating a global struct to output the values into. I know it's not elegant, but that can surely be done.

SplinterGU

you can't return custom types... only can return pointers to custom types.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Grew

My game developer instagram :
https://www.instagram.com/ben_dev_game/