1 registered members (tomaslolo),
1,542
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Stopping a function
#283272
08/06/09 20:30
08/06/09 20:30
|
Joined: Dec 2008
Posts: 56
binsky33333
OP
Junior Member
|
OP
Junior Member
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
User
|
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)
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
Serious User
|
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:
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
Last edited by Claus_N; 08/06/09 20:45.
|
|
|
Re: Stopping a function
[Re: the_mehmaster]
#283306
08/07/09 02:13
08/07/09 02:13
|
Joined: Dec 2008
Posts: 56
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
|
|
|
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
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I may be missing something, but cant you just use return? As in
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: Rasch]
#283338
08/07/09 09:44
08/07/09 09:44
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
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
Serious User
|
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 proc_kill can be used in both C-Script and Lite-C.
Last edited by Claus_N; 08/07/09 09:54. Reason: typo
|
|
|
|