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

[Xotcl] constructor initialization problem

From: <j_marvin_at_localnet.com>
Date: Tue, 9 Dec 2003 06:19:27 -0500

Hi-

In the simple code below I'm working on to simulate an elevator I am
having a little trouble with the
constructor initializing. I get an error that says "cant read
currentFloor...no such variable."
I thought I had set up the constructor right. I tried following this
format from the manual ---

Room instproc setCeilingColor color {
    my set ceilingColor $color
  }

 Room instproc init args {
    my setCeilingColor white
    next
  }

Here is the code. It bombs out in the body of the method named request
when it tries to read the first
$currentFloor variable. I hope I am getting the idea and it is
something kind of simple I am missing.
Please offer a suggestion if what I am doing wrong is apparent to you.

thank you,
marvin

 package require XOTcl;
    namespace import -force xotcl::*
    
    Class Elevator
    
    
   Elevator instproc setInitFloor floor {
   my set currentFloor $floor ;
  }
    
   Elevator instproc init args {
  my set setInitFloor 1;
    next;
   }
    
    Elevator instproc getFloor args {
    puts $currentFloor;
    
    }
    
    Elevator instproc request requestFloor {
        
       
        my set request $requestFloor;
       
    while {$requestFloor > 0} {
        
         if {$currentFloor < $requestFloor} {
            set currentFloor [[Ride getFloor] + 1];
            puts "going up...current floor is $currentFloor";
    }
        if {$currentFloor > $requestFloor} {
            set currentFloor [[Ride getFloor] - 1];
        }
        
        if {$currentFloor == $requestFloor} {
            set requestFloor 0;
            
        }
     }
    
    puts "current floor is $currentFloor";
}

set requestFloor 4;

Elevator Ride;

Ride request $requestFloor;

Ride destroy ;