PDA

View Full Version : Terminate a method mid-stream


debussybunny563
04-01-2011, 08:49 PM
If you have a method in the "During" section of a "While" event, and if you stop the event, the world will give you an "Error During Simulation."

However, this error doesn't happen all the time; it doesn't occur with a simple method like "move forward."

I have posted an example at the bottom of this post.

What I would like to know is if there is any way around this. Yes, I am fully aware of using the "While" statement instead of the "While" event. This does not fit my needs, as this statement will wait until everything within it has finished before stopping; it's basically a loop that you put conditions on.

So, if any of you have a solution, please tell me. :)

reuben2011
04-03-2011, 04:20 PM
Maybe try putting something like this in "While the world is running"

First make a variable and set it to true. I'll call my variable run

if(run == true)
{
run set value to false
//put methods here
run set value to true
}


I hope this helps. I haven't looked at the world (yet.) If this doesn't help, let me know and I'll take a look at your example world to get a better understanding of the situation. ~Cheers!;)

debussybunny563
04-03-2011, 06:44 PM
Thanks for the reply reuben, but say, for example, your method lasted for 10 seconds, and it's on a loop. I want it to terminate whenever, not just when the 10 seconds is over.

Using if and while statements will wait until the method's finished. The only way to truly stop in the middle of an action is to put it in the during section of a while event (note that there's a difference between a while statement and a while event; while statements are located at the bottom of the screen, and events are in the top-right). Unfortunately, in some cases that will lead to an error, which is what I'm trying to get over.

Man, that was a long parenthetical sentence. :)

Mr Kidnapper
04-16-2011, 02:08 PM
The world would do a better explanation than me.
But perhaps instead of asking that the event be turned false, how about you just let the world run and change the Jock's walk method instead?
Ha. I like how he stops to take a breather every two steps.

reuben2011
04-17-2011, 12:56 AM
Well you could use recursion and recall the entire method in order for it to start from the beginning again. However, the cancellation of the method would need to be done within the method and that won't work too well.

You could also have "if continue==true, then..." in front of every executable statement. Although that would be a little tedious.

debussybunny563
04-17-2011, 12:32 PM
You could also have "if continue==true, then..." in front of every executable statement. Although that would be a little tedious.

Yeah, that just doesn't work well. It's a heck of a waste of code, and even then doesn't accomplish the job perfectly.

I'll look in to the recursion method.

Also, Mr. Kidnapper, if you set the wait duration to only 0.25, the jock will still go through the entire 1 second it takes for him to finish the walk instead of pausing right after the quarter of a second.

reuben2011
04-17-2011, 01:52 PM
Yeah, that just doesn't work well. It's a heck of a waste of code, and even then doesn't accomplish the job perfectly.

I'll look in to the recursion method.

Also, Mr. Kidnapper, if you set the wait duration to only 0.25, the jock will still go through the entire 1 second it takes for him to finish the walk instead of pausing right after the quarter of a second.

Just want to know: do you know how recursion works? If you want, I can make an example world showing a good example of recursion. Recursion can get kinda messy though and the results can be unpredictable at times. The HATE making recursive methods (the concept itself is thought-provoking) but sometimes they just get the job done a lot better

debussybunny563
04-17-2011, 04:19 PM
Just want to know: do you know how recursion works? If you want, I can make an example world showing a good example of recursion. Recursion can get kinda messy though and the results can be unpredictable at times. The HATE making recursive methods (the concept itself is thought-provoking) but sometimes they just get the job done a lot better

You hate recursion? 0.o

I got the recursion to work (kinda) in terms of stopping the method. However, it soon causes a stack overflow error because there's no stopping the recursion.

Another problem with the recursion in this situation is that the first method will still run, and the recursion just makes the method overlap with itself, so you can't really stop the action.

I thought I almost had it, but recursion seems to not work either. :(

reuben2011
04-18-2011, 04:15 AM
Yeah, that is what I was afraid of, since the method would just continuously "stack" on itself. I had an idea, but it ended up not working either. :mad:

sfunk
04-19-2011, 08:51 PM
boolean variables are the closest possible thing to getting this idea to work, i have attempted many times to get this "cutting method short" to work. since on my piano porgram i made on alice, i tried using if boolean becomes true, sound would play, but once any key was let go, boolean becomes false, and the only way to get this to work properly is to have it in a infinity loop so it is constantly checking for these methods, but the porblem is, once the variable becomes false, once it is in the infinity loop, it never can become true again.