That's actually a lot shorter than I thought, though some parts confuse me.
-When calculating the distance, is there a reason you didn't get the square root and instead just squared "towerRange" instead?
-When comparing the distant to tower for the first enemy and setting "closestEnemy" to 1, isn't it just going to loop through and set it to the next enemy? It looks like it will focus on each enemy rather than staying locked on without an "exit" from the loop.
-I noticed there is no code in the last IF statement, and the code for focusing on an enemy is what I needed more than the rest. Though I think that IF statement is unnecessary if there is an EXIT in the loop. If the first enemy is in range, then attack and don't check the others. Once it is out of range, check the next one in line.
Still it's a lot shorter than the code I had. And on another note, a question about functions and subroutines. If I declare a local variable inside a function, then use it in a subroutine INSIDE the function, will that variable work, or must it be global, even if the subroutine is used inside the function, like below.
Also I really appreciate the help and advice.
function protocol1()
clickFlag as boolean
clickFlag = 0
repeat
cls
gosub checkForMouseClick
if clickFlag = 1
print "The mouse is being clicked."
endif
sync
until escapekey()
endfunction
checkForMouseCollision:
if mouseclick() = 1
clickFlag = 1
endif
return