Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2017, 4:35:38 PM (6 years ago)
Author:
kohlia
Message:

Crashes when killing the player

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc

    r11638 r11662  
    3535    if((ret = luaL_loadfile(lua, file_path.c_str())) != 0)
    3636    {
     37        orxout(user_error) << "Failed to load level script " + file_path << std::endl;
    3738        this->printLuaError(lua);
    3839        delete api;
     
    4344    if((ret = lua_pcall(lua, 0, LUA_MULTRET, 0)) != 0)
    4445    {
     46        orxout(user_error) << "Level script returned an error" << std::endl;
    4547        this->printLuaError(lua);
    4648        delete api;
     
    8688
    8789    for(auto &api : this->apis_)
    88         api->pawnKilled(pawn_id_iter->second);
     90        api->pawnKilled(pawn_id_iter->second, pawn);
    8991
    9092    this->pawns_.erase(pawn_id_iter->second);
     
    110112void ScriptableController::killPawn(std::string id)
    111113{
    112     auto pawn = this->pawns_.find(id);
    113     if(pawn == this->pawns_.end())
     114    auto pawn = this->getPawnByID(id);
     115    if(pawn == nullptr)
    114116    {
    115117        orxout(user_warning) << "Tried to destroy unknown pawn " << id << std::endl;
     
    117119    }
    118120
    119     pawn->second->kill();
     121    pawn->kill();
    120122}
    121123
     
    141143Pawn *ScriptableController::getPawnByID(std::string id) const
    142144{
     145    if(id == "player" || id == "Player" || id == "PLAYER")
     146        return orxonox_cast<Pawn*>(this->player_->getControllableEntity());
     147
    143148    auto pawn = this->pawns_.find(id);
    144149    return pawn != this->pawns_.end() ? pawn->second : nullptr;
     
    151156    // Yes, this is 'const char*' and not 'std::string' because that's what lua gives us.
    152157    const char* message = lua_tostring(lua, -1);
    153     std::cout << message << std::endl;
     158    orxout(user_error) << message << std::endl;
    154159    lua_pop(lua, 1);
    155160}
Note: See TracChangeset for help on using the changeset viewer.