So in the past couple of days I have decided to learn a bit more about JavaScript and as a lesson to myself I have decided to pursue a project and learn things along the way. I decided to try to make a kind of "bot" for a game. I am trying to write out some code and then just paste it into the HTML console( game is in a web browser). In this game there is an enemy and to kill it you click the button "attack" repeatedly until it dies. Once it dies you are presented with a screen that has a button "Back to Patrolling" which allows you to go back and choose another enemy. What I currently have is
var BTP = document.getElementsByClassName('Patrol-button-name');
checkPatrol(BTP);
function checkPatrol(LEN) {
if (LEN.length > 0) {
document.getElementsByClassName("Patrol-button name")[0].click()}
else {
clickAttack();}
}
function clickAttack() {
return this.document.getElementsByClassName("Attack-Button")[0].click()
return this.checkPatrol(BTP);
}
Basically, checkPatrol uses length to determine if the Patrol button has appeared on the screen. If it has appeared it clicks it however if it hasn't appeared then it calls the clickAttack function which returns the click of the attack button. This segment works but what my question is, is why doesn't it loop again and again until the patrol button is clicked? the clickAttack function chains back into the checkPatrol function so why doesn't it keep looping until the enemy is killed and the patrol button is clicked? When I test this it does the attack once although it seems to me my code is telling it to loop? Why isn't it looping and what am I doing wrong? Could someone then outline a correct way to loop these two functions? Thanks to whoever actually took the time to read this :P.