#JavaScript drag and drop

8 messages · Page 1 of 1 (latest)

untold sigil
#

Hi ..
I am creating a game project , i am replicating the mini game from the cult of the lambs knucklebones.

my problem is when when i drag the rolled dice image to the column cell , it still rolls and give random value. How can i make it still without the randon roll on click ?

the code i used :

    event.preventDefault();
  });

function allowDrop(ev) {
    ev.preventDefault();
  }
  
  function drag(ev) {
    ev.dataTransfer.setData("text", ev.target.id);
  }
  
  function drop(ev) {
    ev.preventDefault();
    const data = ev.dataTransfer.getData("text");
    const diceValue = document.getElementById(data);
    diceValue.classList.add("block");
    ev.target.appendChild(diceValue);
  } ```
acoustic escarp
#

Check whether you are currently dragging the dice before rolling it?

untold sigil
#

i did but yea still the same

acoustic escarp
#

Where are you calling rollDicePlayer1?

untold sigil
#

i will show you the layout

untold sigil
#

it ok i already got it to work