Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 02/26/26 21:35
WFO Training with parallel cores Zorro64
by Martin_HH. 02/26/26 16:03
Zorro version 3.0 prerelease!
by TipmyPip. 02/25/26 16:38
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Martin_HH), 5,115 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
the1, alx, ApprenticeInMuc, PatrickH90, USER0328
19200 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: 934
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 934
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