Erlendftw

Untitled

Nov 7th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addSnap(top, left, numberVal) {
  2.  
  3.     //Check if the data already contains a value for the pair.
  4.     if (contains(sendingData, "[block-" + top + ":" + left + "]", "[/block]")) {
  5.         //The sendingData already contains the current block.
  6.         var getData = splitReduced(sendingData, "[block-" + top + ":" + left + "]", "[/block]");
  7.         var getData_whole = "[block-" + top + ":" + left + "]" + getData + "[/block]";
  8.  
  9.         sendingData = sendingData.replace(getData_whole, "")
  10.     }
  11.  
  12.     //Validate the positions
  13.     var positionValidated = false;
  14.     for (var i = 0; i < validPositions.length; i++) {
  15.         if (validPositions[i][0] == top && validPositions[i][1] == left) positionValidated = true;
  16.     }
  17.  
  18.     if (!positionValidated) {
  19.         //The position is not valid, send a nasty error-message.
  20.         return;
  21.     }
  22.  
  23.     //Create a new block with the data.
  24.     var blockData = '[block-' + top + ':' + left + ']' + numberVal + '[/block]';
  25.     sendingData = sendingData + blockData;
  26.  
  27.     //DEBUG:
  28.     console.log("Added " + top + ":" + left + " to data. Ready to ship.");
  29. }
Advertisement
Add Comment
Please, Sign In to add comment