can_afford() sometimes leads to ERROR:sc2.bot_ai:Error: ActionResult.NotSupported
Ordering a unit by larvae sometimes resulting in getting an error: ERROR:sc2.bot_ai:Error: ActionResult.NotSupported (action: UnitCommand(AbilityId.LARVATRAIN_DRONE, Unit(name='Larva', tag=4314628097), None, False))
I believe this is because the method can_afford() of the class sc2.BotAI sometimes returning true even if we cannot afford the unit. This is happening, I assuming, because there are sequential queue of orders that happening one frame (step) after another, and the information that can_afford() is referring to is not keeping up to date.
Yeah, I think it's the same issue I reported here: https://github.com/Dentosal/python-sc2/issues/38
It should get better if you run Realtime=False, or if you add a small delay in your on_step() method, e.g:
await asyncio.sleep(0.02)
(Need to "import asyncio" at top)
But it's definitely a bug, although it might be a bug in the Blizzard API rather than python-sc2, I'm not sure.
I thought about adding delay too, but thought about it as an ugly hack. Solved problem other way, by checking if larva is able to morph a unit:
larva = self.larvae.random
abilities = await self.get_available_abilities(larva)
if AbilityId.LARVATRAIN_DRONE in abilities:
await self.do(larva.train(DRONE))
There perhaps an artificial delay built in into the game mechanics that prevents larvae to morph units every frame.