Recent Changes - Search:



edit SideBar


Look at the code in MyTherm>>startLoop.

      "set running to true, and use lower priority than the interface"
	running := true.
	[self myLoop] forkAt: 49.

forkAt: sets the priority lower than the desktop (which is at 50). If it is not lower, when the the endless loop in myLoop( the [block] controlled by repeat), you can't change 'running' to false. With the lower priority, other code can change running to false.

     "private. "
     "running is an instance variable, initialized to false to avoid endless
	"use startLoop to change running to true and to give this method lower
	"rand generates between 0 and 1. adjust fudge through MyControl."  
	"heater and cooler are controlled through announcements"

	| oldCurrentTemp newCurrentTemp rand|

	oldCurrentTemp := currentTemp.  
	rand := Random new.
	[ (rand next + fudge + heater - cooler ) >= 0.5 
			ifTrue:  [newCurrentTemp := oldCurrentTemp + bumpTemp] 
			ifFalse: [newCurrentTemp := oldCurrentTemp - bumpTemp].

		self currentTemp: newCurrentTemp.  "currentTemp: also sends announcements"
		oldCurrentTemp := newCurrentTemp.	

		(Delay forSeconds: delaySeconds) wait.
		running ifFalse: 
			[^ nil].  "exits the loop"
	] repeat.
Edit - History - Print - Recent Changes - Search
Page last modified on May 01, 2011, at 10:13 AM