Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,459 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
References? #292280
10/01/09 17:16
10/01/09 17:16
Joined: Oct 2009
Posts: 4
F
FakeTruth Offline OP
Guest
FakeTruth  Offline OP
Guest
F

Joined: Oct 2009
Posts: 4
Hello everybody, I have a question:
How do references work in A7 C-Lite?

I want to create something similar to this:
(In C++ the &[ampersand] sign does this)
Code:
function Add (int& result, int a, int b)
{
	result = a + b;
}

// You can call the function like this
int myResult = 0;
Add(myResult, 5, 7);
// myResult is now 12



What would this function look like in C-Lite?

Many thanks.

Re: References? [Re: FakeTruth] #292282
10/01/09 17:33
10/01/09 17:33
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Code:
function Add (int* myResult, int a, int b)
{
	*myResult = a + b;
}

int myResult = 0;
Add(&myResult, 5, 7);



The reference operator isn't actually needed because lite-c can detect if a function needs a variable or a pointer to the variable.

Last edited by DJBMASTER; 10/01/09 17:37.
Re: References? [Re: DJBMASTER] #292294
10/01/09 19:25
10/01/09 19:25
Joined: Oct 2009
Posts: 4
F
FakeTruth Offline OP
Guest
FakeTruth  Offline OP
Guest
F

Joined: Oct 2009
Posts: 4
Thanks DJBMASTER!

But now I have another question.
This doesn't work when sending a scalar of a vector as a parameter:
Code:
VECTOR myVector;
Add(&(myVector.x), 5, 7);


No matter where I put the & sign, I always get the memory address of the vector, and not of the scalar x

Could anybody help me with this?
Thanks!

Re: References? [Re: FakeTruth] #292297
10/01/09 19:38
10/01/09 19:38
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Hello!

As 'x' is the first member of the VECTOR struct, the address of myVector and its 'x' member are identical.

Therefore
var value = *((var *)&myVector);
is the same as
var value = myVector.x;

Does this answer your question?

Re: References? [Re: FakeTruth] #292299
10/01/09 19:41
10/01/09 19:41
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
I think structs are always passed by a pointer, so you have to take the address of the whole struct, and manipulate it on the other side of the function rather than passing individual members.


Last edited by DJBMASTER; 10/01/09 19:42.
Re: References? [Re: DJBMASTER] #292305
10/01/09 20:16
10/01/09 20:16
Joined: Oct 2009
Posts: 4
F
FakeTruth Offline OP
Guest
FakeTruth  Offline OP
Guest
F

Joined: Oct 2009
Posts: 4
Thanks everybody, I have got it to work!

In the function I first tried float* instead of int* because the scalars in the vector are floats (I think), but this did really weird stuff. So I changed it to var* and this worked perfectly! I can send each scalar along separately grin

Thanks again guys!

PS: If you know anything about the float* weirdness, could you please tell me what that's about?

Re: References? [Re: FakeTruth] #292308
10/01/09 20:34
10/01/09 20:34
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Found this statement in the manual...

"Lite-C additionally supports standard C/C++ integer or floating point variables for cases where you need a higher or smaller range, or better precision. The functions described in this section however use only var as argument and return values."

I think the members of the Vector struct are in-fact vars, which in turn can be a int/float.
Maybe that's why only var will work?

Last edited by DJBMASTER; 10/01/09 20:35.
Re: References? [Re: DJBMASTER] #292416
10/03/09 10:32
10/03/09 10:32
Joined: Apr 2009
Posts: 274
atari98 Offline
Member
atari98  Offline
Member

Joined: Apr 2009
Posts: 274
Maybe itīs an Error


Meine Fun Websiten
www.free4-fun.de.tl

www.gamer-liga-live.de.tl

Meine Game-Projekt Websiten
www.gamer-projects.de.tl
Re: References? [Re: atari98] #292422
10/03/09 12:05
10/03/09 12:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Your right DJBMaster, vectors are by nature a set of three vars.
But the manual is 'blurry' because some functions are apparently "overloaded" to be capable of accepting
a> integer-vectors (never seen one of these though...)
b> standard-vectors (which are just three vars in a row in memory)
c> float-vectors (Ive never seen one used, but look at "_vec()" in the manual)

For a better idea of how the different game structures are built,
try taking a look at the .../GStudio7/includes/aTypes.H file.
JUST DONT ACCIDENTLY CHANGE ANY OF IT! or its re-install GameStudio time....
This will give you a good look at the "guts" of many game object structures.

Have fun...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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