Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,619 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Why??? [Re: benni] #163470
10/27/07 08:18
10/27/07 08:18
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
In any computer is a special memory area that is called the "Stack", thats where local variables are stored. This stack is overwritten by new variables when you return from a function, thats why you can not do something like

return(Copy_c);

the content of copy_c is garbage as soon as you leave the function. In your case its even worse, for some strange reason you are setting copy_c to a pointer to the nullvector, so your overwriting the nullvector in your function and subsequently the nullvector is not null anymore which I guess will crash the engine sooner or later.

A function can return a single value or a pointer but only if the pointer was not local in that function, otherwise the pointer points to some place on the "Stack" and that place is soon overwritten by the next function.

This is ok:

function (VECTOR* A)
{
... return A; // ok because A was defined outside
}

This is not ok:

function (VECTOR* A)
{
VECTOR* B;

... return B; // not ok because B is a pointer that does not exist outside the function
}

But this is ok again:

function (..)
{
var c;

... return c; // ok because single vars are copied when they are returned.
}


Sorry if this sounds confusing but once you get it you'll see programming is very logical, on the internet there are many introductions into programming that are much better than I can give here, like:

http://www.cprogramming.com/tutorial.html#ctutorial

hope this helps...

Re: Why??? [Re: Spirit] #163471
10/27/07 21:05
10/27/07 21:05
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline OP
Newbie

Joined: Oct 2007
Posts: 49
Hildesheim, Germany
O.K., now I understand why it didn't work... programming seems to have some evil traps for beginners
Nevertheless thanks for your advice. I have now finished my script using seperate vars for every axis and it works fine...after this early success I probably have to work on basic understanding more.

Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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