Gamestudio Links
Zorro Links
Newest Posts
About auto hide invisible entitiesl
by Superku
40 minutes 20 seconds ago
LotAmount and PipCost
by tradingest
Today at 15:17
Bump with detail?
by Superku
Today at 15:16
New Zorro version 1.88
by DdlV
Today at 14:33
CCI and SMA Pullback Strategy
by Materz
Today at 13:34
Position Close not possible
by Paul_der_Zweite
Today at 11:28
CSVToHistory.c
by Paul_der_Zweite
Today at 10:43
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 (AndrewAMD, Jason_Rogers, alibaba, 20BN, 3run, Dalla, MatPed, kvm, 2 invisible), 444 Guests and 5 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
egkachai, cepturion, Mon3y, vincitytaymo, just
18058 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: 1194
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 Online
Senior Expert

Registered: 09/13/03
Posts: 6750
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