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
1 registered members (AndrewAMD), 1,310 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
How to return a calling function? #366808
04/07/11 13:39
04/07/11 13:39
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
hi,

this is how I call a function:

Code:
var u_answer=1;
get_answer=show_yes_no();



this is the function:

Code:
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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

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: JibbSmart] #366853
04/07/11 17:22
04/07/11 17:22
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
so what can be the solution? grin


I don't care!
Re: How to return a calling function? [Re: Mahdi] #366857
04/07/11 17:52
04/07/11 17:52
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
by the looks of this, you've got u_answer declared locally and globally

guessing without seeing more code but...
you're declaring var u_answer = 1 only locally but have a global variable which isn't being set.

change var u_answer = 1;
to
u_answer = 1;

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 Offline
Expert
FoxHound  Offline
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!

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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