Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript Drag and drop not working

gamedev12.png

Okay so what I'd like to do is drag the dog food in the inventory slot onto the dog food bowls. Right now my code registers that the dog food is being dragged and it even knows that it's in inventory slot 0. Furthermore it knows that the dropzone (objZone4) has particular coordinates of "361,237,401,274". However, when I drag the dog food over the food bowls, all I see is a red cancellation sign and I'm not seeing the square drop zone box. What's interesting is if I leave the current room and climb up the ship some, there's a drop zone that DOES work using the same code. Am I missing something? The code will enter dragStart() but is unable to enter dragOver() because the drop zone isn't working correctly. Why would it work in one room if it doesn't work in another?

//get the drop zone and let it be droppable
this.objZone4 = document.getElementById("objZone4");
this.objZone4.addEventListener('dragover', this.dragOver);
this.objZone4.addEventListener('drop', this.dragDrop);

dragStart(e) {
//it still knows coordinates of the food bowl
console.log('hello good sir: ' + e.target.id);

//assigns to beingDragged the current inventory slot
//simply evaluates to 0,1,2,3,4,5,6, or 7 so it knows the inventory slot
//for instance it knows if dog food is in inventory slot 0
document.getElementById("beingDragged").innerText = (parseInt((e.target.id)[7]) - 1);
}

dragOver(e) {
//allow drop into square
e.preventDefault();
}

dragDrop(e) {
//not working
}
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom