Dentosal / python-sc2

A StarCraft II bot api client library for Python 3
MIT License
586 stars 182 forks source link

Fix move_camera #184

Closed Arcia125 closed 5 years ago

Arcia125 commented 5 years ago

I was trying to make an automatic camera and came across an error when trying to use the BotAI._client.move_camera method. Here's a simple example that tests the method. Before this fix it throws ValueError: Protocol message RequestAction has no "action" field.

camera_example.py

from sc2 import run_game, maps, Race, Difficulty
from sc2.player import Bot, Computer
from sc2.bot_ai import BotAI

class CameraMoveExampleBot(BotAI):
    async def move_camera(self):
        """
        ERROR:sc2.main:AI step threw an error
        Traceback (most recent call last):
        File "./sc2/main.py", line 63, in _play_game_ai
            await ai.on_step(iteration)
        File "./src/camera_example.py", line 24, in on_step
            await self.move_camera()
        File "./src/camera_example.py", line 20, in move_camera
            return await self._client.move_camera(self.game_info.map_center)
        File "./sc2/client.py", line 286, in move_camera
            x=position.x, y=position.y)
        ValueError: Protocol message RequestAction has no "action" field.
        ERROR:sc2.main:resigning due to previous error
        """
        return await self._client.move_camera(self.game_info.map_center)

    async def on_step(self, iteration):
        if iteration == 0:
            await self.move_camera()
            print('successfully moved camera')

if __name__ == '__main__':
    run_game(maps.get("AbyssalReefLE"), [
        Bot(Race.Zerg, CameraMoveExampleBot()),
        Computer(Race.Random, Difficulty.VeryEasy)
    ], realtime=False)