Gamestudio Links
Zorro Links
Newest Posts
How is this possible ? winning percentage 100%
by MatPed
50 minutes 13 seconds ago
Next contest?
by Michael_Schwarz
Today at 10:33
Help! 1.88.6 Crashes <5 minutes after clicking Trade!
by jcl
Today at 10:28
WFO
by jcl
Today at 10:27
TA-Lib not updated
by jcl
Today at 10:24
CyberCycle Adaptive Cy
by OptimusPrime
Today at 05:26
video memory and d3d_texfree
by Superku
Yesterday at 11:17
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
16 registered (CocaCola, kvm, MatPed, Iglarion, AndrewAMD, brax, Michael_Schwarz, Mio, 2 invisible), 454 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
fandi, Deedee, avgtrader, aventador, gokhanuck
18103 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: 1202
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: 6771
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