alice-teacher While and events

Don Slater dslater at andrew.cmu.edu
Mon Sep 12 17:10:29 EDT 2011


Is your question Alice will not let you create the "while something is true" event from the events editor? Or that you cannot drag the "while" tile into the code block for an event? I have been able to do this in the latest Mac version of Alice 2.2.

One solution is to create a new method for the world, put your while statement inside of the new method, and then call that method from the event.

There is also in the "while something is true" event. This gives you an event block that looks like:

	while <none> is true
		Begin: <nothing>
		During: <nothing>
		End: <nothing>

Imagine that I have two penguins ("jim" and "joe") that are on the polar ice cap and I want them to move toward each other until they are two meters apart. This event would look like

	while <jim.distanceTo(joe) is greater than 2 meters> is true
		// this code is executed once, the first time the while statement becomes true
		Begin: DoTogether
				jim turnToFace joe
				joe turn to face jim

		// this code is executed continuously as long as while statement is true
		During: DoTogether
				jim move forward .5 meters
				joe move forward .5 meters

		// this code would be executed one time when the while statement becomes false
		End: Do In Order
				jim say "Hi, Joe!"
				joe say "Hi, Jim!"

The following is also acceptable (we could assume that joe and jim are already facing each other)

	while <jim.distanceTo(joe) is greater than 2 meters> is true
		// nothing will happen the first time the while statement becomes true
		Begin: <nothing>

		// this code is executed continuously as long as while statement is true
		During: DoTogether
				jim move forward .5 meters
				joe move forward .5 meters

		// nothing will happen when the while statement becomes false
		End: <nothing>

You may also create a  "while something is true" event in the event editor. If you right-click on that code block, the context menu will give you a "change to" option which allows you to change this 

	"while something is true" event to a "when condition = <None> becomes true, do <Nothing>" event.



Let me know if you have any questions.

Later,
Don Slater



On Sep 12, 2011, at 10:56 AM, Emily Higgins wrote:

> Hello All -
> I cannot get the While function into the Events.  Neither can my students.  Any thoughts?
> Emily
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers



More information about the alice-teachers mailing list