Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, EternallyCurious, howardR, 1 invisible), 623 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to return a vector from a function #473783
08/14/18 23:24
08/14/18 23:24
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
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.

Re: How to return a vector from a function [Re: jumpman] #473786
08/15/18 03:39
08/15/18 03:39
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
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

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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

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

Powered by UBB.threads™ PHP Forum Software 7.7.1