Gamestudio Links
Zorro Links
Newest Posts
offset +1
by Grat. 06/20/19 13:22
Getting Errors
by Tavasy. 06/20/19 12:58
FXCM: "Can't connect to price server"
by DdlV. 06/20/19 11:48
Bring the old grin back!
by jcl. 06/20/19 05:54
A8 and Draw_Line3D (SOLVED)
by Dooley. 06/19/19 21:27
Data Execution Prevention Strikes Again
by Dooley. 06/19/19 15:38
assert
by jcl. 06/19/19 14:59
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
13 registered members (JeyKey II, kvm, Grat, Michael_Schwarz, MatPed, Ayumi, AndrewAMD, brax, 2 invisible), 616 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
redye, rhe2564, Qw3rty, Dal, Carson
18238 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,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
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
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,842
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

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