[Xotcl] constructor initialization problem

Gustaf Neumann neumann at wu-wien.ac.at
Tue Dec 9 14:41:02 CET 2003


 
 Hi marvin,
 in order to get an instance variable into the scope of an instproc, you have
 to import it via the method instvar

 Below is a simplified version of you script.

 best regards
-gustaf
==============================================
package require XOTcl;
namespace import -force xotcl::*
    
Class Elevator -parameter {{currentFloor 1}}

Elevator instproc request requestFloor  {
    my instvar currentFloor

    while {1} {
	if {$currentFloor < $requestFloor} {
	    incr currentFloor
            puts "going up...current floor is $currentFloor";
	}
        if {$currentFloor > $requestFloor} {
	    incr currentFloor -1
            puts "going down...current floor is $currentFloor";
        }
        if {$currentFloor == $requestFloor} {
            break
        }
    }
    puts "current floor is $currentFloor";
}

set requestFloor  4;

Elevator Ride;
Ride request $requestFloor;
Ride destroy ;
==============================================
-- 
Univ.Prof. Dr.Gustaf Neumann
Abteilung für Wirtschaftsinformatik
WU-Wien, Augasse 2-6, 1090 Wien



More information about the Xotcl mailing list