|
|
|
Help!
by VoroneTZ. 10/14/25 05:04
|
|
|
|
|
|
2 registered members (Grant, joenxxx),
9,921
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Expert
|
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: Filipe]
#73457
05/08/06 12:36
05/08/06 12:36
|
Joined: Feb 2005
Posts: 3,687 Hessen, Germany
Tempelbauer
Expert
|
Expert
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: Xarthor]
#73459
05/08/06 20:22
05/08/06 20:22
|
Joined: Jul 2000
Posts: 8,973 Bay Area
Doug
Senior Expert
|
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).
|
|
|
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
OP
Expert
|
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: Doug]
#73462
05/09/06 21:28
05/09/06 21:28
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
OP
Expert
|
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!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|