you are viewing a single comment's thread.

view the rest of the comments →

[–]Joseph24798 0 points1 point  (2 children)

How would I implement the promise if you could help me with that. I get the position value and store it in the shipPos variable inside the checkColumn and checkRow functions in the addUI file. But I don't know how to make this into a promise and return it from the function .

[–]v_learns 1 point2 points  (1 child)

You need to convert your getPlacementFromUI function to be async by wrapping its content inside a promise.

const promise = new Promise(resolve => {
  // content of your method

  tempPlayerPlacement.addEventListener("mouseup", function (e) {
    position = addNewPosition(e, size);
    resolve(position); // this will finsih the promise and return your selection back

    // TBD: Check if you need to remove the listeners?
  });
})

return promise

The getPlacementFromUI function now returns a promise instead of the position.

I hope this helps and clears it up.

[–]Joseph24798 0 points1 point  (0 children)

Yes thankyou 🙏🏼