View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] constructor initialization problem

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Tue, 9 Dec 2003 14:41:02 +0100

 
 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