Your bot will ‘spawn’ into the game when it connects, but that doesn’t necessarily mean that the match has started. The match start when the ‘last’ bot connects.
When writing your bot you have to decide if you want it to be looping/using-cpu cycles or computing on stale state before the match actually starts or not. You can take one of a few options for detecting the start of the match.
match_started
event. This is useful, but if your bot disconnects and re-connects for any reason during the match, this even will NOT fire again.// default to true in-case we miss the start
let matchInProgress = true
bot.on('match_started', async(matchInfo) => {
console.log(`The match has started`)
matchInProgress = true;
})
startTime
if (bot.matchInfo().startTime) {
matchInProgress = true
}
A more robust approach may be to frequently check for the start of the match until the match starts
// Wait for the match to start
while(true) {
if (bot.matchInfo()?.startTime) {
console.log("Match started! Starting code")
startMyBotActions()
break
}
console.log("Waiting for match to start...")
await bot.waitForMilliseconds(500);
}