Index: code/branches/ScriptableController/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10046)
+++ code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10047)
@@ -3,28 +3,22 @@
 --orxonox.execute("orxout message test " .. k)
 
+-- Set some test variables
 x = 1.1
 y = 2.2
 z = 3.3
 
+--os.execute("sleep " .. 2)
 
+-- Get a local pointer to a scriptcontroller
 local ctrl = orxonox.ScriptController:getScriptController()
+
+-- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
   ctrl:moveToPosition_beta(x, y, z)
 end
 
---ctrl.moveToPosition(x,y,z)
---
+-- Output the newctrlid variable we set from the C++ code
 if newctrlid ~= nil then
   orxonox.execute("orxout message test " .. newctrlid)
-end
-
-local docks = orxonox.Dock:getNumberOfActiveDocks()
-local docklist = {}
-for i = 0, docks-1 do
-  table.insert(docklist, orxonox.Dock:getActiveDockAtIndex(i))
-end
-local dock = docklist[1]
-if dock ~= nil then
-    dock:dock()
 end
 
Index: code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10046)
+++ code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10047)
@@ -6,4 +6,5 @@
 
 #include "ControllerDirector.h"
+#include "ScriptController.h"
 #include "core/CoreIncludes.h"
 
@@ -32,4 +33,5 @@
         this->entity_ = NULL;
         this->pTrigger_ = NULL;
+        this->context_ = context;
     }
 
@@ -64,7 +66,19 @@
         * triggered our event. 
         */
-       static int ctrlid = 0;
-       // preparationTo(trigger);
-       // setNewController(controller);
+       static int ctrlid = 1;
+       bool prepok = preparationToTakeControl(trigger);
+       if( prepok == true) 
+       {
+         /* Create a scriptcontroller object */
+         ScriptController *newctrl = new ScriptController(this->context_);
+
+         /* Make the player we were given its slave */
+         newctrl->setPlayer(this->player_);
+
+         /* Start controlling that object */
+         newctrl->takeControl(ctrlid);
+       }
+       else
+         return;
        
        /* Set up a luastate to use for running the scripts */
@@ -90,30 +104,34 @@
 
 	
-    /*bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) {
-
-	    this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger);
+    bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) 
+    {
+        this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger);
         this->player_ = NULL;
 
         orxout() << "Preparation to take Control!" << endl; 
+
         // Check whether it is a player trigger and extract pawn from it
         if(this->pTrigger_ != NULL)
         {
-            
-            player_ = this->pTrigger_->getTriggeringPlayer();  //Get the object which triggered the event.
+            // Get the object which triggered the event.
+            this->player_ = this->pTrigger_->getTriggeringPlayer();  
+
+            // Check if there actually was a player returned.
+            if( this->player_ == NULL) return false;
         }
         else
         {
-            orxout() << "ControllerDirector::preparationToTakeControl Not a player trigger, can't extract pawn from it.." << endl;
+            orxout() << "ControllerDirector::preparationToTakeControl " 
+              << "Not a player trigger, can't extract pawn from it.." << endl;
             return false;
         }
 
-	
 	this->entity_ = this->player_->getControllableEntity();
 	assert(this->entity_);
 
-    return true;
-
+        return true;
     }
 
+    /* // Currently unused
     void ControllerDirector::setNewController(Controller * controller) {
 
@@ -124,10 +142,8 @@
         this->player_->pauseControl();
         this->entity_->setController(controller);
-        this->setControllableEntity(this->entity_);
-
-
-
+        this->player_->startControl(this->entity_);
+        //this->setControllableEntity(this->entity_);
     }
-*/
+    */
        
     
Index: code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.h
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.h	(revision 10046)
+++ code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.h	(revision 10047)
@@ -48,8 +48,10 @@
 	
 	
-	
+            /* Take over control of a given object */
 	    void takeControl(Controller * controller, BaseObject * trigger);
 	    bool preparationToTakeControl(BaseObject * trigger);
-	    void setNewController(Controller * controller);
+
+            // currently unused
+	    //void setNewController(Controller * controller);
 	
 
@@ -57,9 +59,8 @@
         private:
 	   
-	   PlayerInfo* player_;
-
-       ControllableEntity* entity_; 
-
-	   PlayerTrigger * pTrigger_;
+            PlayerInfo* player_;
+            ControllableEntity* entity_; 
+            PlayerTrigger * pTrigger_;
+            Context* context_;
 	
 
Index: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10046)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10047)
@@ -28,4 +28,5 @@
 
 #include "ScriptController.h"
+#include "infos/PlayerInfo.h"
 #include "core/CoreIncludes.h"
 #include "worldentities/ControllableEntity.h"
@@ -42,16 +43,29 @@
         RegisterObject(ScriptController);
         //set_controlled(CE);
+        this->ctrlid_ = 0;
     }
 
-    void ScriptController::set_luasrc(std::string lsrc)
+    void ScriptController::takeControl(int ctrlid)
     {
-        this->luasrc=lsrc;
+        orxout() << "ScriptController: Taking control" << endl;
+        orxout() << "This-pointer: " << this << endl;
+        this->ctrlid_ = ctrlid;
+        this->entity_ = this->player_->getControllableEntity();
+        assert(this->entity_);
+
+        this->entity_->setDestroyWhenPlayerLeft(false);
+        this->player_->pauseControl();
+        this->entity_->setController(this);
+        this->setControllableEntity(this->entity_);
     }
 
-    void ScriptController::set_controlled(ControllableEntity* toControl)
-    {
-        this->controlled=toControl;
-    }
-    
+    /* Yet to be implemented and tested */
+    //void ScriptController::yieldControl()
+    //{
+        //this->player_->startControl(this->entity_);
+        //this->setActive(false);
+        //this->controllableEntity_ = NULL;
+    //}
+
     void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
@@ -62,5 +76,5 @@
     const Vector3& ScriptController::getPosition()
     {
-        return this->controlled->getPosition();
+        return this->entity_->getPosition();
     }
 
@@ -70,5 +84,11 @@
       orxout() << "Great success!" << std::endl;
 
-      /* Loop over all the scriptcontrollers currently present in the game */
+      /* Debugging: print all the scriptcontroller object pointers */
+      for(ObjectList<ScriptController>::iterator it = 
+        ObjectList<ScriptController>::begin(); 
+        it != ObjectList<ScriptController>::end(); ++it)
+      { orxout() << "Have object in list: " << *it << endl; }
+
+      /* Find the first one with a nonzero ID */
       for(ObjectList<ScriptController>::iterator it = 
         ObjectList<ScriptController>::begin(); 
@@ -76,5 +96,6 @@
       { 
         // TODO: do some selection here. Currently just returns the first one
-        return *it; 
+        if( (*it)->getID() > 0 )
+          return *it; 
       
       }
@@ -82,16 +103,29 @@
     }
 
+    void ScriptController::tick(float dt)
+    {
+        /* If this controller has no entity entry, do nothing */
+        if( !(this->entity_) )
+          return;
+
+        //orxout() << "Rotating!" << endl;
+
+        //this->entity_->rotateYaw(-1.0f * 100.0f * dt);
+        //this->entity_->rotatePitch(0.8f * 100.0f);
+
+        SUPER(ScriptController, tick, dt);
+    }
 
 
     void ScriptController::moveToPosition_beta(float x, float y, float z )
     {
-        /* The section commented out here below throws segfaults */
-        //const Vector3 local=getPosition();
-        //const Vector3 target=Vector3(x,y,z);
-        //Vector3 way=target-local;
+        //const Vector3 local = this->getPosition();
+        const Vector3 target = Vector3(100*x,100*y,100*z);
+        //Vector3 way = target-local;
+        orxout() << "Moving This-pointer: " << this << endl;
        
         
-        //this->controlled->lookAt(target);
-        //this->controlled->moveFrontBack(way.length());      
+        this->entity_->lookAt(target);
+        this->entity_->moveFrontBack(-1000*target.length());      
 
   
@@ -99,4 +133,5 @@
         orxout()<<x<<"  "<<y<<"  "<<z<<endl;
     }
+
 
     /* TODO:    hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl 
Index: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10046)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10047)
@@ -38,5 +38,5 @@
 {  // tolua_export
     class _OrxonoxExport ScriptController // tolua_export 
-       : public ArtificialController
+       : public ArtificialController, public Tickable
     {  // tolua_export
         public:
@@ -48,8 +48,11 @@
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             
+            void takeControl(int ctrlid);
+            void setPlayer(PlayerInfo* player) { this->player_ = player; }
            
-            void set_luasrc(std::string);
-            void set_controlled(ControllableEntity*);
+            //void set_luasrc(std::string);
+            //void set_controlled(ControllableEntity*);
 
+            virtual void tick(float dt);
 
             // LUA interface
@@ -59,6 +62,7 @@
            
             static ScriptController* getScriptController();
+
+            int getID() { return ctrlid_; }
             
-              /* virtual void tick(float dt);*/ 
 
             // tolua_end
@@ -66,7 +70,9 @@
 
         private:
-        	std::string luasrc;		// name of the LUA-sourcefile that shall be executed->see XMLPort-function
-
-            ControllableEntity* controlled; //entity controlled by this SC
+            // name of the LUA-sourcefile that shall be executed->see XMLPort-function
+            std::string luasrc;		
+            PlayerInfo* player_;
+            ControllableEntity* entity_;
+            int ctrlid_;
 
 
