Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
How do I make the world stop!
Old
Chris101b
Senior Member
 
Chris101b's Avatar
 
Status: Offline
Posts: 361
Join Date: Jun 2007
Default How do I make the world stop! - 06-02-2008, 02:12 AM

If I have something on a loop like someone shooting at you all the time, how do I make him stop when he dies. I was curios because when I made Infiltration, the guy that shot rockets at you kept shooting even after he died. When he would fall down, he would glitch around (trying to look at you) and shoot up into the air. And the boss at the end would keep trying to chase you even after he was dead. I just wanted to know if it was possible to solve this problem if I ever felt like making another game.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 06-02-2008, 08:00 AM

With that description, it's hard to go into much detail but doesn't sound like you're looking for detail anyway.

This is the sort of thing that a "while" statement is good at. It will continue to loop while something is true (say someone is alive - you do have to create a variable to test) and then stop when the condition goes false.

For more information, either look in one of the texts or Dick Baldwin's tutorials. Actually the information is not Alice specific - nearly all languages have this capability.

In Alice, I would avoid the "event While" if possible - it can cause problems when ending a loop. Again, that is covered in some other forum postings and I think in one of the tutorials.
   
Reply With Quote
hmmmm.....
Old
ulrich200
Guest
 
Status:
Posts: n/a
Unhappy hmmmm..... - 06-10-2008, 12:29 PM

this is tricky . . . I tried using a variable (see attached file) but it did not work. I will keep looking in to this and come back to you if I find anything
Attached Files
File Type: a2w variable demonstration.a2w (452.5 KB, 70 views)
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 06-10-2008, 04:18 PM

After the program starts, the while statement evaluates again only after its block of code completes one itteration. That test occurs before the next execution of the code block. With an infinite loop (which is unnecessary here, since the while is a loop in this case - see attached), the first pass through the code block never ends and thus the while condition is never evaluated.
Attached Files
File Type: a2w mod variable demo.a2w (448.3 KB, 77 views)

Last edited by DrJim; 06-11-2008 at 07:15 AM. Reason: Clarification of original posting
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 06-11-2008, 12:01 AM

Quote:
Originally Posted by DrJim View Post
A while statement evaluates only after its block of code completes one itteration. With an infinite loop (which is unnecessary here, since the while is a loop in this case - see attached), the code block never ends and thus the while condition is never evaluated.
DrJim,

If I understand what you are saying correctly, I believe that you have it backwards. I don't recall ever investigating this issue in Alice, but in C, C++, Java, and C#, the conditional clause in a while loop is evaluated before the code block inside the while loop executes. Thus, the code in the block will execute only if the conditional clause evaluates to true the first time it is executed. Otherwise, that code will not be executed and the entire while loop structure will effectively bypassed.

That is the reason for the existence of the do-while loop (which, as I recall, doesn't exist in Alice). With a do-while loop, the conditional clause is not evaluated until after the code block has executed. Therefore, the code block in a do-while loop is guaranteed to execute at least once regardless of the result of evaluating the conditional clause.

I suspect that this is also true in Alice but I'm not certain.

However, this doesn't answer the original question posed by Chris101b. I didn't try to answer the original question because it was too general. Also, Chris101b didn't seem to be particularly anxious about getting an answer to the question. (He stated: "I just wanted to know if it was possible to solve this problem if I ever felt like making another game.") Of course, the answer is yes. It is possible to solve the problem. At least it is possible to solve the problem of the guy thrashing around after he is dead. If Chris101b can illustrate his question with a short and concise example program, I will be happy to take a look at it and tell him how it can be solved.

Regards,
Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free Scratch tutorials: http://www.dickbaldwin.com/tocHomeSchool.htm
Free Java/C#, etc. tutorials: http://www.dickbaldwin.com/toc.htm

Last edited by DickBaldwin; 06-11-2008 at 12:04 AM. Reason: Clarification
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 06-11-2008, 07:32 AM

Dick is correct. I implied something in my original posting that was not true. I've changed the wording of the posting so hopefully it is now clear.

As Dick notes, in Alice a while is always evaluated at the start of a loop. You can see this in the example by making the default test value zero instead of one - in that case the gun never fires. If the default is one, the gun just continues to fire since the test is never made again due to the infinite loop.

An interesting test is if you leave the default test value at one but reset to zero before enlarging the cone. In this case, whether the while is evaluated first seems to depend on it's position in the program. If the while block is first, the gun fires - if not, it doesn't. Don't know that I have seen this documented - can anyone give a reference?

Also, as an aside, many languages have an "until" function which actually goes through the loop block once before making its test and then evaluates the test condition at the end of each execution of the block. This sounds a little like what Dick describes as a "do-while." Regardless of the name, this is not supported in Alice.

As a final, mostly historical note, one of the reasons I answered the original question was that the "while" and "until" constructs are relatively new additions to programming languages (though they still have been around probably since before the majority of forum members were born ). They were a very useful addition - but because they were "add-ons", there was not a lot of consistancy in either naming or positioning of the conditional test at first - and this has stayed around long enough that beginning programmers may just avoid them because of these inconsistancies. I believe Alice does follow the current standards for the While statement - but since no language specification for Alice is available (a major lack IMO), I can't say for sure.
   
Reply With Quote
Reply


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.