Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:30:34+00:00 2026-05-19T01:30:34+00:00

var userNam; var whoIsMove; var playerColor; var playerToMoveID; var currentPlayerID = $(#currentPlayerID).val(); $(document).ready(function ()

  • 0
     var userNam;
 var whoIsMove;
 var playerColor;
 var playerToMoveID;
 var currentPlayerID = $("#currentPlayerID").val();

 $(document).ready(function ()
 {
     //$("#moveMessage").html("Waiting for update...");
     var refreshId = setInterval("GetMoves(), GetWhoIsMove()", 1000);
     var to;
     var from = 's65';
     var pieceName;

     playerColor = $("#playerColor").val();
     currentPlayerID = $("#currentPlayerID").val();
     /// playerToMoveID = $("#playerToMove").val();

     if (currentPlayerID == playerToMoveID)
     {
         if (playerColor.toString() == "white")
         {
             $(".whiteP").draggable({
                 //revert: 'invalid',
                 //helper: 'clone',
                 cursor: 'move',
                 containment: 'checkerBoard',
                 start: function (event, ui)
                 {
                     //$(".square").hover(function ()
                     //{
                     //    from = $(this).attr('id')
                     //});
                     pieceName = $(this).attr('id');
                     //alert($from);
                 }
             });
         } else if (playerColor.toString() == "black")
         {
             $(".blackP").draggable({
                 //revert: 'invalid',
                 //helper: 'clone',
                 cursor: 'move',
                 containment: 'checkerBoard',
                 start: function (event, ui)
                 {
                     //$(".square").hover(function ()
                     //{
                     //    from = $(this).attr('id')
                     //});
                     pieceName = $(this).attr('id');
                     //alert($from);
                 }
             });
         }
     }
     $("div.square").droppable({
         accept: '.chessPiece',
         drop: function (event, ui)
         {
             to = $(this).attr('id');
             //alert(currentPlayerID);
             $.post(
            "/Game/MakeMove",
            {
                To: to,
                From: from,
                PieceName: pieceName,
                UserName: $("#userName").val(),
                UserID1: $("#userID1").val(),
                UserID2: $("#userID2").val(),
                GameID: $("#gameID").val()

            },
             function (data)
             {
                 if (data == 'good')
                 { }
                 else if (data == 'bad')
                 {
                     alert("sorry not you turn");
                 }
             }
            );

         }
     });
 })

function GetWhoIsMove()
{
                    $.getJSON(
                    "/Game/GetWhoIsMove",
                    {
                        GameID: $("#gameID").val()
                    },
                    function (data)
                    {
                        playerToMoveID = data;
                    }
                    );
}

That line is causing problems:
if (currentPlayerID == playerToMoveID)

It always return false. I have checked values, and currentPlayerID is depeding on what player is curretnly logged in and playerToMoveID is pulled up from data base.

While I used those variables in alert(), they showed correct values for both players. So I must ask, what’s wrong with that if() ?

It should be alwyas true for exactly one player, until he make his move.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:30:34+00:00Added an answer on May 19, 2026 at 1:30 am

    The problem is that you’re comparing the value of playerToMoveID before you set it.

    You set the value of playerToMoveID as the result of a function call caused by the setInterval.

    When the if statement fails, it’s because the if statement is being evaluated before the setInterval has had a chance to fire.

    You need to come up with a way to ensure that playerToMoveID is set before the if statement. A setInterval won’t cut it — there’s no guarantee that it will run in a timely manner.

    The reason it “works” when you check the values is probably that you’ve changed the program enough that by the time you get to the second alert box that displays the playerToMoveID value, it’s had a chance to run the GetWhoIsMove function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery(document).ready(function(){ var panelContainer = jQuery('div#panels'); jQuery('<div id=tabs></div>').insertBefore(panelContainer); panelContainer.find('div.panel').each(function(n){ jQuery('div#tabs').append('<a class=tab href=#' + (n+1) +
Here is the javascript: function checkusername() { var username = $(#username).val(); $.post(usernamecheck.php, {'username':username}, function
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
<script type='text/javascript'> function formValidator(){ // Make quick references to our fields var username =
How can we store dynamic variables into cookie . var username = ($(#username).val()); how
I have the following script inside a HTML page: <script> function Test(){ alert(i got
For example: var $myContainer = $('#myContainer'); $myContainer.html(someHtml); var width = $myContainer.height(); var height =
var i : integer; i := 1234567; Given the above, I want the string
var insInvoice = new NpgsqlCommand( @INSERT INTO invoice_detail( invoice_id, invoice_detail_id, product_id, qty, price, amount)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.