Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9195 in orxonox.OLD


Ignore:
Timestamp:
Jul 5, 2006, 9:29:01 AM (18 years ago)
Author:
snellen
Message:

scripttrigger can be created form within a script

Location:
branches/presentation/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/presentation/src/lib/script_engine/script.cc

    r9193 r9195  
    2626CREATE_SCRIPTABLE_CLASS(Script, CL_SCRIPT,
    2727                    addMethod("addObject", ExecutorLua2<Script,const std::string&, const std::string& >(&Script::addObject))
     28                    ->addMethod("registerClass", ExecutorLua1<Script,const std::string&>(&Script::registerClass))
    2829                    ->addMethod("selectFunction", ExecutorLua2ret<Script, bool, const std::string&, int >(&Script::selectFunction))
    2930                    ->addMethod("executeFunction", ExecutorLua0ret<Script,bool >(&Script::executeFunction))
     
    7879bool Script::loadFile(const std::string& filename)
    7980 {
    80    this->setName(filename);
    8181   std::string filedest(ResourceManager::getInstance()->getDataDir());
    8282   filedest += "scripts/" + filename;
     
    9595   if(error == 0)
    9696   {
    97      
     97     currentFile = filename;
    9898     error = lua_pcall(luaState, 0, 0, 0);
    9999
    100100     if(error == 0)
    101101     {
    102       currentFile = filename;
    103102      return true;
    104103     }
     
    360359   //this->registerClass(std::string("Vector"));
    361360    this->registerClass("ScriptTrigger");
    362     this->registerClass("AttractorMine");
     361  //  this->registerClass("AttractorMine");
    363362
    364363   return success;
     
    366365 
    367366 
    368  bool Script::registerClass( const std::string& className)
     367 void Script::registerClass( const std::string& className)
    369368 {
    370369   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     
    379378       tmpObj.name = "";
    380379       registeredObjects.push_back(tmpObj);
     380       return;
     381     }
     382   }
     383 
     384 }
     385
     386 bool Script::classIsRegistered(const std::string& type)
     387 {
     388   for(std::list<WorldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
     389   {
     390     if( (*it).type == type)
     391     {
    381392       return true;
    382393     }
    383394   }
    384395   return false;
    385  
    386  }
    387 
    388  bool Script::classIsRegistered(const std::string& type)
     396 }
     397
     398
     399
     400 bool Script::objectIsAdded(const std::string& name)
    389401 {
    390402   for(std::list<WorldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
    391403   {
    392      if( (*it).type == type)
     404     if( (*it).name == name)
    393405     {
    394406       return true;
     
    396408   }
    397409   return false;
    398  }
    399 
    400 
    401 
    402  bool Script::objectIsAdded(const std::string& name)
    403  {
    404    for(std::list<WorldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
    405    {
    406      if( (*it).name == name)
    407      {
    408        return true;
    409      }
    410    }
    411    return false;
    412 
    413 
    414  }
     410
     411
     412 }
  • branches/presentation/src/lib/script_engine/script.h

    r9061 r9195  
    3232    bool loadFile(const std::string& filename);
    3333    void addObject( const std::string& className,const std::string& objectName);
     34    void registerClass(const std::string& className);                           //!< Register a class but dont add any instances
    3435
    3536    /// QUERRYING
     
    6465    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
    6566    bool registerStandartClasses();                   //!< Register all the classes that the script might need
    66     bool registerClass(const std::string& className); //!< Register a class but dont add any instances
    6767    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
    6868    bool objectIsAdded(const std::string& name);      //!< Checks wheter the object "name" has already been added to the script
  • branches/presentation/src/world_entities/script_trigger.cc

    r9193 r9195  
    5252  this->toList(OM_COMMON);
    5353
     54  radius = 10;
    5455  returnCount = 1;
    5556  scriptFinished = false;
     
    7273 
    7374  }
     75 
    7476}
    7577
     
    137139  BaseObject* targetEntity = ClassList::getObject(target, CL_WORLD_ENTITY);
    138140
    139   if (targetEntity != NULL)
     141      if (targetEntity != NULL)
    140142  {
    141143    this->setTarget(dynamic_cast<WorldEntity*>(targetEntity));
     
    216218void ScriptTrigger::setScript(const std::string& file)
    217219{
    218 
    219220  ScriptManager* scriptManager = State::getScriptManager();
    220221  if (scriptManager != NULL)
     
    224225    if(script != NULL)
    225226    {
     227      printf("setting script to %s\n",file.c_str());
    226228      scriptIsOk = true;
    227229    }
Note: See TracChangeset for help on using the changeset viewer.