Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Stopping a function #283272
08/06/09 20:30
08/06/09 20:30
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Ok so here is my problem basically i am trying to switch between functions and such. When i switch to another function, i want to be able to stop the other function so everything in it does not work anymore. Is there a command that can do that? Not like sleep or wait... But something that will completely quit the function?

Last edited by binsky33333; 08/06/09 20:37.
Re: Stopping a function [Re: binsky33333] #283275
08/06/09 20:42
08/06/09 20:42
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline
User
the_mehmaster  Offline
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
#EDIT: I clicked on the icon on the side.. Didn't know it was c-script. Maybe this will help you anyways..

Use goto to skip to the end of a function:
(Lite-C)
Code:
function something()
{
//some instructions
if(needtoquit)goto somethingend;
//more instructions
somethingend:
wait(1);
}


There are better methods, but i can't get them out of the top of my head..

Last edited by the_mehmaster; 08/06/09 20:44.
Re: Stopping a function [Re: binsky33333] #283276
08/06/09 20:44
08/06/09 20:44
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
The only function to kill processes that comes to my mind is proc_kill, and it can't be used for that purpose.

It is however possible to do something like this:
Code:
var functionIsRunning = 0;	// A global variable

function theFunction()
{
	// Set the variable to non-zero
	functionIsRunning = 1;
	
	// Run the function as long as functionIsRunning is non-zero
	while(functionIsRunning != 0)
	{
		... // Code
	}
}



This way you can stop the function by setting 'functionIsRunning' to 0.

Edit: Never use 'goto', please frown

Last edited by Claus_N; 08/06/09 20:45.
Re: Stopping a function [Re: binsky33333] #283277
08/06/09 20:46
08/06/09 20:46
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
I'm not sure if you can call a function and then destroy the calling function because i think that messes up the path of execution.

Can't you just put the function to call at the end of the calling function. When the called functions finishes, it will return to the original function and then that will return. Maybe i misunderstood the question.

Re: Stopping a function [Re: Claus_N] #283278
08/06/09 20:48
08/06/09 20:48
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline
User
the_mehmaster  Offline
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Quote:
Edit: Never use 'goto', please

I know, i know.. Very bad programming practice..

Blinsky, use Claus_N's method.

Re: Stopping a function [Re: the_mehmaster] #283306
08/07/09 02:13
08/07/09 02:13
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
ok guys, thank you!

Re: Stopping a function [Re: binsky33333] #283309
08/07/09 04:55
08/07/09 04:55
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I may be missing something, but cant you just use return?
As in
Code:
function firstone()
{
    while(1)
    {
       if(xxx==0)
       {
           nextfunction();
           return;
       }
       wait(1);
    }
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Stopping a function [Re: EvilSOB] #283335
08/07/09 09:14
08/07/09 09:14
Joined: Jun 2008
Posts: 428
Rasch Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
If it is in a while loop just use break then.

Code:
function breaking()
{
    while(1)
    {
       if(x == 0)
       {
           do_this();
           break; // Stops the while loop and continues after it
       }
       wait(1);
    }
    // Here could be more code
}



Re: Stopping a function [Re: Rasch] #283338
08/07/09 09:44
08/07/09 09:44
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive done it this way cause he said he wanted to "kill" the function.

You could also look into "proc_kill" in the manual, but I dont know if it is C-Script...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Stopping a function [Re: EvilSOB] #283342
08/07/09 09:54
08/07/09 09:54
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Yeah, 'return' or 'break' could be used as well, I guess it's a matter of personal preference and the situation smile

proc_kill can be used in both C-Script and Lite-C.

Last edited by Claus_N; 08/07/09 09:54. Reason: typo

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