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
2 registered members (AndrewAMD, degenerate_762), 1,309 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Return Vector not possible after 1 frame #448874
02/24/15 18:13
02/24/15 18:13
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Hello everybody,

I have yet another problem I am not sure about why it occurs.
I have the following code-example:

Quote:

function calculate()
{
wait(1);
return (vector(100,200,300));
}



function main()
{
VECTOR* the_endresult = calculate();

if (the_endresult.x == 100 & the_endresult.y == 200 & the_endresult.z == 300)
{printf("Works");}
}



I just want to return a vector, but as long as the wait(1);-command exists, this whole code does not work.
In my actual (much longer code) I have a while-loop in my return function (which contains wait-commands) so I can't leave them out.
But only 1 single wait-command and the return-function won't work.

I also don't want to globally save my numbers because this function might be opened multiple times at the same time with different numbers to work with, so a global variable would be overwritten by all functions and that might cause weird results.

Is there any good way I can still return my Vector?

Re: Return Vector not possible after 1 frame [Re: Yking] #448876
02/24/15 18:58
02/24/15 18:58
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
"wait" returns from a function like "return" ,it returns back to the calling function (if there's one),in this case it returns back to main ,and by then that function wich assigned the value to the vector already returned through wait.., after which wait is supposed to resume to the next code line where the vector is returned ,but all to late for the calling function , it makes no sense to me why one would want a "wait" if you return with a vector anyway ..

or I am confused in What's suppose to be , and my understanding of this failed terrible lol

jb

edit : oh I forgot , if you move the "wait" to the last line your function would work as you wrote it there however senseless outside a loop as it is there ...

Last edited by Wjbender; 02/24/15 19:01.

Compulsive compiler
Re: Return Vector not possible after 1 frame [Re: Wjbender] #448877
02/24/15 19:39
02/24/15 19:39
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
oh and if you need to compare you should use && instead of &

although I'm sure that was just a mistake on your post..

you can also pass the vector through the function's argument list ,something similar to

void getvalue (var x , var y, var z)

or

void getvalue (VECTOR* that_vector)



Compulsive compiler
Re: Return Vector not possible after 1 frame [Re: Wjbender] #448889
02/25/15 08:41
02/25/15 08:41
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Thanks for the help,

This code I gave is only an example, in my actual code there would be a while-loop that contains a c_move. Every loop the c_move is used to move an entity a little bit. Well it doesn't really matter, I cant use return this way so I have to figure out something else I guess smirk

(Passing through the functions argument list does not work in my code, I dont want to call the function again)

Re: Return Vector not possible after 1 frame [Re: Yking] #448891
02/25/15 10:04
02/25/15 10:04
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Originally Posted By: Yking
Thanks for the help,

This code I gave is only an example, in my actual code there would be a while-loop that contains a c_move. Every loop the c_move is used to move an entity a little bit. Well it doesn't really matter, I cant use return this way so I have to figure out something else I guess smirk

(Passing through the functions argument list does not work in my code, I dont want to call the function again)


"return" exits the function , so any while loop will stop being executed when return is executed from within that function .

while (1)
{
if(bla) then return bla; // this loop wil shut down
wait (1);
}

now look at what I told you about wait so that you understand my confusing post better.

in the manual goto index and type return

read where it says , a function that contains a wait loop can not return a parameter because wait already returns to the calling function before the final return is executed ..

jb

Last edited by Wjbender; 02/25/15 10:09.

Compulsive compiler
Re: Return Vector not possible after 1 frame [Re: Wjbender] #448894
02/25/15 10:12
02/25/15 10:12
Joined: Aug 2014
Posts: 7
F
Fred_Flintstones Offline
Newbie
Fred_Flintstones  Offline
Newbie
F

Joined: Aug 2014
Posts: 7
So someting like this wouldn't work?

Code:
function calculate(VECTOR* a_vector)
{
wait(1);
vec_set(a_vector,vector(100,200,300)); 
}

function main()
{
VECTOR* the_endresult;	
calculate(the_endresult);
wait_for_my(calculate); //wait(1);
if (the_endresult.x == 100 && the_endresult.y == 200 && the_endresult.z == 300)
{printf("Works");}
}


Re: Return Vector not possible after 1 frame [Re: Fred_Flintstones] #448897
02/25/15 10:39
02/25/15 10:39
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
that should work however you need to prevent passing an empty pointer laugh

VECTOR *result=malloc (sizeof (vector));
calculate (result);
wait_for_my(calculate); or wait_for (calculate);
etc etc....

jb


Compulsive compiler

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