Changeset 10046 for code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
- Timestamp:
- May 7, 2014, 2:03:18 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
r10035 r10046 1 1 /* 2 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. 2 * First try of a ControllerDirector. Target: An event occurs in the levelTry.oxw 3 * file, which is "heard" by an object of the type of this class. It then SHOULD 4 * (because it is not working) execute the party function. 3 5 */ 4 6 … … 20 22 ControllerDirector::ControllerDirector(Context* context) : ArtificialController(context) 21 23 { 22 //Working 24 // Register the object with the framework 23 25 RegisterObject(ControllerDirector); 26 27 // output a message to ensure we know the constructor was run 24 28 orxout()<<"hello universe constructor"<< endl; 25 29 26 this->player_=NULL; 27 this->entity_=NULL; 28 this->pTrigger_=NULL; 30 // Initialize member variables 31 this->player_ = NULL; 32 this->entity_ = NULL; 33 this->pTrigger_ = NULL; 29 34 } 30 31 35 32 36 void ControllerDirector::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 34 38 SUPER(ControllerDirector, XMLPort, xmlelement, mode); 35 39 36 37 orxout()<<"ControllerDriector::XMLPort An instance of ControllerDirector has been created."<< endl;40 orxout()<< "ControllerDirector::XMLPort " 41 << "An instance of ControllerDirector has been created." << endl; 38 42 } 39 43 40 44 void ControllerDirector::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 41 45 { 46 // Call the xmleventport functions of the classes we derive from 42 47 SUPER(ControllerDirector, XMLEventPort, xmlelement, mode); 43 48 44 XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", takeControl, xmlelement, mode); 45 49 // Add an event sink for a "takeControl" event, which leads to the 50 // function takeControl() being called. 51 XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", 52 takeControl, xmlelement, mode); 46 53 } 47 54 … … 49 56 50 57 51 void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) { 58 void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) 59 { 60 /* Output a message confirming that the function was called */ 61 orxout()<<"test takecontrol."<< endl; 52 62 63 /* First, we set up a new controller to attach to the unit that 64 * triggered our event. 65 */ 66 static int ctrlid = 0; 53 67 // preparationTo(trigger); 54 68 // setNewController(controller); 55 LuaState * test = new LuaState(); 56 orxout()<<"test takecontrol."<< endl; 57 test->doFile("testscript.lua"); 58 69 70 /* Set up a luastate to use for running the scripts */ 71 LuaState * ls = new LuaState(); 72 73 /* Assemble a string to define a controller id variable in lua space */ 74 std::stringstream tmp; 75 tmp << "newctrlid = " << ctrlid; 76 std::string todo = tmp.str(); 77 78 /* Run the string using the luastate created earlier */ 79 ls->doString(todo); 80 81 /* Now run the script on this controller. This will still have the above 82 * variable "newctrlid" defined, which means it can make use of it. 83 */ 84 ls->doFile("testscript.lua"); 85 86 /* Increase the controller ID so we have a different one for 87 * the next time it is triggered */ 88 ctrlid += 1; 59 89 } 60 90
Note: See TracChangeset
for help on using the changeset viewer.