Blizzard / s2client-api

StarCraft II Client - C++ library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
1.66k stars 281 forks source link

Observation()->GetChatMessages() missing messages in real time mode #249

Closed Frigerius closed 6 years ago

Frigerius commented 6 years ago

Hi, I have the following issue. I'm creating a simple test-bot and I try to read the chat messages to parse some commands. While starting a game in non-realt ime, in each OnStep() I get each send message with calling Observation()->GetChatMessages(). But if I start the sc2::Coordinator with real time set to true I don't get all messages, as if some get scipped.

Am I doing smth. wrong or is this a bug?

Frigerius commented 6 years ago

A little update to my issue. By following Coordinator::Update() I found the method ObservationImp::UpdateObservation() which updates the observation of my Agent. By adding a std::cout to the following code I can see any message in my console:

chat_.clear();
for (auto& message : response_->chat()) {
    chat_.push_back({message.player_id(), message.message()});
    std::cout << "sc2_client " << message.message() << std::endl;
}

but if I try to read them in OnStep() most of the messages are not shown as if they get deleted before I can read them.

Frigerius commented 6 years ago

OK, now I got it. ControlInterface::GetObservation() is called as often as Coordinator::Update(). But ControlInterface::IssueEvents(...) is only called if the following not returns...

if (observation_imp_->current_game_loop_ == observation_imp_->previous_game_loop) {
   return false;
}

And this is why you do not get all chat messages if you run the bot in real time -.-

Frigerius commented 6 years ago

My workaround is adding

virtual void OnChatMessagesReceived(const std::vector<ChatMessage>& /*messages*/) {}

to sc2_client.h and calling it in ControlInterface::IssueEvents(...) if the observation has any messages.