I'm working on a very basic tower defense game using Javascript in the Code.org online software. What I'm looking for is to click on a tower, it follows the cursor, and then releases when you click a spot on the map. I don't understand why my code isn't working, however. I appreciate the help! I know I'm a beginner and this is probably a very obvious question but it would mean a lot if someone could help me. Thanks!
EDIT: I haven't dealt with the last part yet. All that's included in this program segment is clicking on a tower, and having it follow your mouse cursor.
var mouseYPosition;
var towerIsSelected = false;
function moveTower() {
onEvent("screen1", "mousemove", function() {
setPosition("towerOne", mouseXPosition, mouseYPosition);
})}
onEvent("screen1", "mousemove", function(event){
mouseXPosition = event.x;
mouseYPosition = event.y;
});
onEvent ("towerOne", "click", function() {
towerIsSelected = true;
return towerIsSelected;
});
if (towerIsSelected) {
moveTower();
}