Index: code/branches/ScriptableController/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10045)
+++ code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10046)
@@ -9,6 +9,13 @@
 
 local ctrl = orxonox.ScriptController:getScriptController()
---orxonox.ScriptController:moveToPosition(x, y, z)
+if ctrl ~= nil then
+  ctrl:moveToPosition_beta(x, y, z)
+end
+
 --ctrl.moveToPosition(x,y,z)
+--
+if newctrlid ~= nil then
+  orxonox.execute("orxout message test " .. newctrlid)
+end
 
 local docks = orxonox.Dock:getNumberOfActiveDocks()
Index: code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10045)
+++ code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10046)
@@ -1,4 +1,6 @@
 /*
-First try of a ControllerDirector. Target: An event occurs in the levelTry.oxw file, which is "heard" by an object of the type of this class. It then SHOULD (because it is not working) execute the party function.
+ * First try of a ControllerDirector. Target: An event occurs in the levelTry.oxw
+ * file, which is "heard" by an object of the type of this class. It then SHOULD
+ * (because it is not working) execute the party function.
  */
 
@@ -20,13 +22,15 @@
     ControllerDirector::ControllerDirector(Context* context) : ArtificialController(context)
     {
-	//Working
+        // Register the object with the framework
         RegisterObject(ControllerDirector);
+
+        // output a message to ensure we know the constructor was run
         orxout()<<"hello universe constructor"<< endl;
 
-	   this->player_=NULL;
-	   this->entity_=NULL;
-	   this->pTrigger_=NULL;
+        // Initialize member variables
+        this->player_ = NULL;
+        this->entity_ = NULL;
+        this->pTrigger_ = NULL;
     }
-
 
     void ControllerDirector::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -34,14 +38,17 @@
         SUPER(ControllerDirector, XMLPort, xmlelement, mode);
 
-	
-        orxout()<<"ControllerDriector::XMLPort An instance of ControllerDirector has been created."<< endl;
+        orxout()<< "ControllerDirector::XMLPort " 
+          << "An instance of ControllerDirector has been created." << endl;
     }
 
     void ControllerDirector::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
     {
+        // Call the xmleventport functions of the classes we derive from
         SUPER(ControllerDirector, XMLEventPort, xmlelement, mode);
 
-        XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", takeControl, xmlelement, mode);
-
+        // Add an event sink for a "takeControl" event, which leads to the
+        // function takeControl() being called.
+        XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", 
+          takeControl, xmlelement, mode);
     }
 
@@ -49,12 +56,35 @@
 
 
-    void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) {
+    void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) 
+    {
+       /* Output a message confirming that the function was called */
+       orxout()<<"test takecontrol."<< endl;
 
+       /* First, we set up a new controller to attach to the unit that
+        * triggered our event. 
+        */
+       static int ctrlid = 0;
        // preparationTo(trigger);
        // setNewController(controller);
-        LuaState * test = new LuaState();
-        orxout()<<"test takecontrol."<< endl;
-        test->doFile("testscript.lua");
-        
+       
+       /* Set up a luastate to use for running the scripts */
+       LuaState * ls = new LuaState();
+       
+       /* Assemble a string to define a controller id variable in lua space */
+       std::stringstream tmp;
+       tmp << "newctrlid = " << ctrlid;
+       std::string todo = tmp.str();
+
+       /* Run the string using the luastate created earlier */
+       ls->doString(todo);
+
+       /* Now run the script on this controller. This will still have the above
+        * variable "newctrlid" defined, which means it can make use of it.
+        */
+       ls->doFile("testscript.lua");
+
+       /* Increase the controller ID so we have a different one for
+        * the next time it is triggered */
+       ctrlid += 1;
     } 
 
Index: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10045)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10046)
@@ -67,5 +67,8 @@
     ScriptController* ScriptController::getScriptController()
     {
+      /* Output a message that confirms this function was called */
       orxout() << "Great success!" << std::endl;
+
+      /* Loop over all the scriptcontrollers currently present in the game */
       for(ObjectList<ScriptController>::iterator it = 
         ObjectList<ScriptController>::begin(); 
@@ -83,21 +86,16 @@
     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;
+       
+        
+        //this->controlled->lookAt(target);
+        //this->controlled->moveFrontBack(way.length());      
 
-       const Vector3 local=getPosition();
-       const Vector3 target=Vector3(x,y,z);
-
-       Vector3 way=target-local;
-
-       
-       this->controlled->lookAt(target);
-
-        this->controlled->moveFrontBack(way.length());      
-
-
-        /*orxout()<<x<<"  "<<y<<"  "<<z<<endl;*/
-
-
-
-         
+  
+        /* This works fine */
+        orxout()<<x<<"  "<<y<<"  "<<z<<endl;
     }
 
Index: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10045)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10046)
@@ -50,5 +50,4 @@
            
             void set_luasrc(std::string);
-
             void set_controlled(ControllableEntity*);
 
