Gamestudio Links
Zorro Links
Newest Posts
Help with Data import to T1
by AndrewAMD
45 minutes 48 seconds ago
Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding?
by AndrewAMD
Today at 03:54
Correlation -1.#IND00
by AndrewAMD
01/21/19 17:37
Basic thread safety question
by Superku
01/20/19 18:15
Blog Post: Get Historical Data from Darwinex REST API w/ Zorro
by AndrewAMD
01/19/19 22:19
Reseting a static variable - the next day
by OptimusPrime
01/19/19 19:48
Train algorithms separatery
by 3dgamelight
01/18/19 10:37
AUM Magazine
Latest Screens
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Who's Online
12 registered (Iglarion, AndrewAMD, Michael_Schwarz, ags, chsmac85, kvm, ibne, alibaba, 3 invisible), 431 Guests and 6 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
laz, ramonne, SibJac, Evael, NRW
18156 Registered Users
Topic Options
Rate This Topic
#473783 - 08/15/18 01:24 How to return a vector from a function
jumpman Offline
Serious User

Registered: 04/17/02
Posts: 1220
Loc: ny
Is it possible? I want to do some calculations in a function and return a vector. I tried doing renaming the function to VECTOR* super_function() but it gives me a struct error on return.
_________________________
A8 Pro 8.47

Top
#473786 - 08/15/18 05:39 Re: How to return a vector from a function [Re: jumpman]
Superku Offline
Senior Expert

Registered: 09/13/03
Posts: 6795
Loc: Kiel (Germany)
You could add a vector pointer as an argument/ parameter, (and/) or use a static vector:

Code:
void foo(VECTOR* v, var x, var y, var z)
{
	v->x = x;
	v->y = y*2;
	v->z = z*3;
}

VECTOR* foo(VECTOR* v, var x, var y, var z)
{
	v->x = x;
	v->y = y*2;
	v->z = z*3;

	return v; // now you can use the function as an argument where VECTOR* is expected
}

// same function but accepts NULL as "v" as well
VECTOR* foo(VECTOR* v, var x, var y, var z)
{
	static VECTOR _v;
	if(!v) v = &_v;
	v->x = x;
	v->y = y*2;
	v->z = z*3;

	return v;
}

VECTOR* foo(var x, var y, var z)
{
	static VECTOR _v;
	_v.x = x;
	_v.y = y*2;
	_v.z = z*3;

	return &_v;
}

_________________________
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Superku The Game

Severely outdated footage: http://store.steampowered.com/app/407570

Top


Moderator:  HeelX, TSG_Torsten 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de