Alice Community  

Go Back   Alice Community > Alice 2 > Bugs and Troubleshooting

Reply
 
Thread Tools Display Modes
Terminate a method mid-stream
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Exclamation Terminate a method mid-stream - 04-01-2011, 07: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.
Attached Files
File Type: a2w example1.a2w (521.2 KB, 6 views)


Last edited by debussybunny563; 12-21-2012 at 12:00 AM.

|--------------------------------------------------------------------------------------------------|
|Link to weapons collection: http://www.alice.org/community/showthread.php?t=7368 |
|--------------------------------------------------------------------------------------------------|

I have been dead for quite some time now; not much hope for resurrection.
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-03-2011, 03: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
Code:
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!


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Default 04-03-2011, 05: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.


Last edited by debussybunny563; 12-21-2012 at 12:00 AM.

|--------------------------------------------------------------------------------------------------|
|Link to weapons collection: http://www.alice.org/community/showthread.php?t=7368 |
|--------------------------------------------------------------------------------------------------|

I have been dead for quite some time now; not much hope for resurrection.
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 04-16-2011, 01: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.
Attached Files
File Type: a2w Your Jock.a2w (523.2 KB, 13 views)
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-16-2011, 11:56 PM

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.


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Default 04-17-2011, 11:32 AM

Quote:
Originally Posted by reuben2011 View Post
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.


Last edited by debussybunny563; 12-21-2012 at 12:00 AM.

|--------------------------------------------------------------------------------------------------|
|Link to weapons collection: http://www.alice.org/community/showthread.php?t=7368 |
|--------------------------------------------------------------------------------------------------|

I have been dead for quite some time now; not much hope for resurrection.
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-17-2011, 12:52 PM

Quote:
Originally Posted by debussybunny563 View Post


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


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Default 04-17-2011, 03:19 PM

Quote:
Originally Posted by reuben2011 View Post
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.


Last edited by debussybunny563; 12-21-2012 at 12:00 AM.

|--------------------------------------------------------------------------------------------------|
|Link to weapons collection: http://www.alice.org/community/showthread.php?t=7368 |
|--------------------------------------------------------------------------------------------------|

I have been dead for quite some time now; not much hope for resurrection.
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-18-2011, 03: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.


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
sfunk
Senior Member
 
sfunk's Avatar
 
Status: Offline
Posts: 1,112
Join Date: Mar 2011
Location: I don't know
Default 04-19-2011, 07: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.


If you are stuck on a project, check out the tutorials I made here at this link:

http://alice.org/community/showthread.php?p=36778#post36778

There are lots of tutorials on it so far, including some youtube videos, check it out

Or..

Go to my youtube channel to check out my alice 2.2 tutorials I have there..

http://www.youtube.com/user/sfunk1992?feature=mhsn
   
Reply With Quote
Reply

Tags
terminate method, while loop, while statement

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.