Gamestudio Links
Zorro Links
Newest Posts
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (VoroneTZ, TipmyPip), 9,297 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Jota, krishna, DrissB, James168, Ed_Love
19169 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
return(parameter); not working in A6.40.4 #73455
05/07/06 13:55
05/07/06 13:55
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Hi,
sorry if this has been asked before, but I just did a search on this and didn't find anything.

Ok here is my problem:
I use this simple Code:

font arial_16 = "Arial",1,16;

var test_return = 0;
var return_value = 0;

panel return_pan
{
pos_x = 10;
pos_y = 100;
layer = 4;
digits = 0,0,3,arial_16,1,test_return;
flags = visible;
}

function gimme_a_return()
{
return_value = 2;
wait(-1);
return(return_value);
}

function test_the_return()
{
test_return = gimme_a_return();
}



But it doesn't work.
The var "test_return" stays always 0, at least thats what my panel shows me.

Anyone know something about that?

Thanks in advance.
Thunder

Re: return(parameter); not working in A6.40.4 [Re: Xarthor] #73456
05/08/06 12:20
05/08/06 12:20
Joined: May 2005
Posts: 338
Brasil
Filipe Offline
Senior Member
Filipe  Offline
Senior Member

Joined: May 2005
Posts: 338
Brasil
return doesn't work in functions with wait or sleep...
when a function hits a sleep or wait, it returns the value of the wait to the calling function.
like this:

function return1()
{
wait(2);
return(1); //this function returns 2, not 1.
}
function return2()
{
wait(32); //this function will return 32, not 2
wait(12);
return(2);
}

maybe this behaviour changed in 6.4, i got this results from a test i did in 6.31.4, but i think i should still be the same. but then in your case it would return -1, not 0... maybe for negative values it returns 0, i don't know...

hope i could help,
Filipe

Re: return(parameter); not working in A6.40.4 [Re: Filipe] #73457
05/08/06 12:36
05/08/06 12:36
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
filipe is right. i had the same problem too about a few months...
but i´ve thought this would be only a problem in while-loops

alternative you can avoid the problem over a global variable. but before you do, check if it´s necessary

Re: return(parameter); not working in A6.40.4 [Re: Tempelbauer] #73458
05/08/06 16:14
05/08/06 16:14
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
That sucks.
Sorry but it really does.
So I guess I gotta do the work around, caus I need the wait. (Caus there is a while loop in the function, so there is automaticly a wait(1); )

Thanks for the response guys, this was really freaking me out, didn't know that there is this damn limitation.

Thanks again.

Re: return(parameter); not working in A6.40.4 [Re: Xarthor] #73459
05/08/06 20:22
05/08/06 20:22
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
It's been like this since A4. If you understand how the code is executed, you'll see why. For example, follow the numbers in "()"s (1,2,3, etc):

Code:

function gimme_a_return() // << (3) this function was called
{
return_value = 2; // << (4) return value is given a value
wait(-1); // << (5) this function is on hold for one frame,
// so control is returned to the calling function

return(return_value); // << (8) We're back after waiting a frame,
// we return a value but, since the calling function
// has already continued without us, we just
// throw away this value.
}

function test_the_return() // << (1) If you call this function first
{
test_return = gimme_a_return(); // << (2) gimme_a_return is called...
// << (6) gimme_a_return was put on hold
// before it got to its return value so
// test_return is assigned the wait value
} // << (7) This fuction is finished





Quote:

So I guess I gotta do the work around, caus I need the wait. (Caus there is a while loop in the function, so there is automaticly a wait(1); )




While loops don't always need waits. It is perfectly legal to do something like this:

Code:

i = 0;
while(i<20)
{
i += 1;
}



Just remember that without the wait, everything happens in one frame so you need to be sure that your loop isn't too big (otherwise things will slow down a lot).


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: return(parameter); not working in A6.40.4 [Re: Doug] #73460
05/08/06 20:47
05/08/06 20:47
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Yeah that came to my mind after posting here, I mean how the code is executed and why this causes these results.
Ok one question though doug:
How about adding a while loop to check if the called function has already returned a value:
Code:

function gimme_a_return()
{
wait(-1);
return(2);
}

function test_return()
{
var i;
i = gimme_a_return();
while(!i) { wait(1); }
//do stuff with i
}



This seems not to work either, and I mean its pretty logic I guess.
I already made the workaround with the global vars wasn't a problem at all, just liked the idea to return a value to check if the function failed or what it worked out.

thanks
Thunder

Re: return(parameter); not working in A6.40.4 [Re: Xarthor] #73461
05/09/06 20:43
05/09/06 20:43
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
Your code doesn't work because gimme_a_return returns a value when it hits the wait. This is "by design" and makes logic sense.

Using global vars is an okay solution but, if this is a entity function, I would suggest using one of the entity skills/flags instead (so you can call the function more than once).

However, if people need a better solution, a "call and wait" command might be an interesting idea for a feature request.


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: return(parameter); not working in A6.40.4 [Re: Doug] #73462
05/09/06 21:28
05/09/06 21:28
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Well its not an entity function so its working fine.
yeah i do understand the logic behind this.

But still a "call and wait" command would be kinda cool, wouldn't it.

thanks Doug!


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