Bennu Game Development

English Forums => Helpdesk => Topic started by: Grew on August 07, 2014, 07:54:36 AM

Title: Function return custom type
Post by: Grew on August 07, 2014, 07:54:36 AM
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.)
Title: Re:Function return custom type
Post by: handsource-dyko on August 07, 2014, 01:25:00 PM
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.
Title: Re:Function return custom type
Post by: SplinterGU on August 07, 2014, 06:11:40 PM
you can't return custom types... only can return pointers to custom types.
Title: Re:Function return custom type
Post by: Grew on August 08, 2014, 07:38:20 AM
Thanks for your answers !