|
2 registered members (AndrewAMD, TipmyPip),
13,353
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to return a calling function?
#366808
04/07/11 13:39
04/07/11 13:39
|
Joined: Aug 2007
Posts: 74
Mahdi
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2007
Posts: 74
|
hi, this is how I call a function:
var u_answer=1;
get_answer=show_yes_no();
this is the function:
function show_yes_no()
{
while(key_space==off)
{
if(key_cul==on)
{
u_answer=1;
}
if (key_cur==on)
{
u_answer=2;
}
wait(1);
}
return(u_answer);
}
The returning value is always 0. But u_answer can never be 0. Because I never set it to 0!
I don't care!
|
|
|
Re: How to return a calling function?
[Re: Mahdi]
#366839
04/07/11 16:18
04/07/11 16:18
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
At a guess, since I haven't tried this, wait(1) automatically returns zero so that the calling function can continue to execute. In this case, the "return" only serves to terminate the function (which was about to happen anyway by reaching the end of the function).
Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: How to return a calling function?
[Re: Mahdi]
#366935
04/08/11 04:28
04/08/11 04:28
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
Expert
|
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
Since you have U_answer declared in the first function you do not need it to be returned by the second function. However it should not even work if it is declared in the first function but only if it is declared globally.
Here is how functions work. When they are called from the first function that function stops and waits for that second function to finish or use a wait instruction, which basically adds that second function to a function manager to be called after all the other functions have had their turn. The only reason you need to return a value is if you need that information in the first function.
Now if you really need that info try this
while(key_space==off) { get_answer=show_yes_no();
wait(1); }
function show_yes_no() { if(key_cul==on) { u_answer=1; } if (key_cur==on) { u_answer=2; } return(u_answer); }
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
|
|
|