Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (TedMar), 1,420 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Passing by reference/value #171842
12/08/07 17:47
12/08/07 17:47
Joined: Dec 2003
Posts: 179
Chameleon_Man Offline OP
Member
Chameleon_Man  Offline OP
Member

Joined: Dec 2003
Posts: 179
In c-script, how do I pass a var by reference and value? What about making a function return a value? Thanks.

Last edited by Chameleon_Man; 12/08/07 17:57.
Re: Passing by reference/value [Re: Chameleon_Man] #171843
12/08/07 18:22
12/08/07 18:22
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hi,

Quote:

how do I pass a var by reference and value?



By value: function func(my_var) {...}
By reference: function func(&my_var) {...}

By using '&' you can also pass arrays as parameters.

Quote:

What about making a function return a value?




function func(my_var) {
return(my_var*2);
}

In C-Script you can return vars only.
However, as vars can also be used to save pointers you can return pointers to entities, strings a.s.o. as well.

Re: Passing by reference/value [Re: Fenriswolf] #171844
12/08/07 20:30
12/08/07 20:30
Joined: Dec 2003
Posts: 179
Chameleon_Man Offline OP
Member
Chameleon_Man  Offline OP
Member

Joined: Dec 2003
Posts: 179
Error(0): Syntax error - local var can't be passed as vector.

I get this error when I try to pass as reference. My code looks a little like this...

Function Main {
var momentum=0;
jump(momentum);
}

Function jump(&momentum) {
...
}

Re: Passing by reference/value [Re: Chameleon_Man] #171845
12/09/07 04:46
12/09/07 04:46
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Local vars are vars that have been created insinde the function.
Move 'var momentun=0;' before your function main() and it'll work. (This way you'll make it a global var)


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Passing by reference/value [Re: EpsiloN] #171846
12/09/07 06:16
12/09/07 06:16
Joined: Dec 2003
Posts: 179
Chameleon_Man Offline OP
Member
Chameleon_Man  Offline OP
Member

Joined: Dec 2003
Posts: 179
That's a quick fix to the problem, but I'd like to avoid using global variables. Too many globals are a sign of bad programming...

Re: Passing by reference/value [Re: Chameleon_Man] #171847
12/09/07 07:45
12/09/07 07:45
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Quote:

Too many globals are a sign of bad programming...



Ok , so we're all bad programmers
If you sit down and think about it for a minute , you have one 'you' pointer wich is global and is used by 100s of functions at the same time. How ? I'll leave that up to you , because a sign of bad programming is exactly that , not knowing how you could use one global var/pointer in many diffrent functions between two frames.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

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