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

  • SEARCH
  • Home
  • 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 8023637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:37:06+00:00 2026-06-04T22:37:06+00:00

I am currently working on a multiplayer game in Javascript, and I seem to

  • 0

I am currently working on a multiplayer game in Javascript, and I seem to have a very peculiar problem with my PlayerList data-structure/object.

Here is the object:

var PlayerList = function(){
    this.list = {};
}

The object has several methods that I added by doing…

PlayerList.prototype.method = function(){...}

The methods are: addPlayer, removePlayer, playerInList, findPlayer, jsonify and unjsonify.
I am having a huge problem with unjsonify. Here is the code:

PlayerList.prototype.unjsonify = function(jsonList){
    var object = JSON.parse(jsonList);
    var li = new PlayerList();
    console.log(li.list.x);
    console.log(li.list.y);
    console.log(li.list);
    //insert the fake player objects from the fake list into the new list as real player objects
    for(p in object.list){
        var pObj = object.list[p];
        //create real player object
        var player = new Player(pObj.name, pObj.x, pObj.y, pObj.velX, pObj.velY);
        li.addPlayer(player);
    }
    return li;
}

The reason for doing it this way is because if I just parse the jsonList object sent by the server, the resulting object has the correct structure, but none of the methods a PlayerList should have.

Here’s the problem: I noticed later, when I go through the PlayerList.list and draw each player, I get this error:

Uncaught TypeError: Object NaN has no method ‘getX’

As it turns out, for some reason when I created a new PlayerList in unjsonify it had two extra fields, x and y, both set to NaN. The problem occurs here:

PlayerList.prototype.unjsonify = function(jsonList){
    var object = JSON.parse(jsonList);
    var li = new PlayerList();

For some very odd reason, li is not a new empty PlayerList like it should be. It contains two extra variables, x and y, both set to NaN. Even weirder, not only is it not a new empty list, it contains all the players that are currently on the server – something that seems impossible to me because the first time the client gets the package containing the json player list it doesn’t even have a past version of itself to go off of.

To top it off, if you look at the block of code for unjsonify, console.log(li.list.x) and console.log(li.list.y) both output undefined, but then console.log(li.list) outputs an Object that has (in addition to all players on the server) fields x and y set to NaN.

I am totally lost on how this could even happen. It seems like one of these bugs no one could solve because they just don’t make any sense. But if someone has the slightest idea on how to help me that would be greatly appreciated!

I should note that before I had this PlayerList object, I simply used an object primitive without any methods and did everything manually (e.g. pList.username = player to add players, etc…) and everything worked (I could see other players move on my screen, etc.) But since this is getting pretty large at this point, I wanted to add some structure hence I created this PlayerList object that should make my code more structured and pretty but thus far has only caused more problems than anything else.

  • 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-06-04T22:37:08+00:00Added an answer on June 4, 2026 at 10:37 pm

    Your PlayerList has no .addPlay method.

    While you’re working with the code it is easier to name your variables where they’re readable.

     function PlayerList() {
                    this.list = [];
             };
                //
     PlayerList.prototype.unjsonify = function (jsonList) {
              var jsonLst = JSON.parse(jsonList),
                        myPlayerList = new PlayerList(),
                        player,
                        jsonItem;
                    //
          for (var i = 0; i < jsonLst.list.length; i++) {
                        jsonItem = jsonLst.list[i];
                        //
                        player = new Player(jsonItem.name, jsonItem.x, jsonItem.y, jsonItem.velX, jsonItem.velY);
    
                        myPlayerList.list.push(player);
    
                    };
                    return myPlayerList;
                };
    

    I’ve changed your Player.list from an object to an array.

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

Sidebar

Related Questions

I'm currently working on a school (matrix multiplier) project and I have a problem.
I am currently working on a small personal multiplayer game project. I am using
Hello Facebook developpers community, I'm currently working on a multiplayer online game with HTML/JS.
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
I`m currently working on a script, and I have the following situation. function somnicefunction()
Im currently working on a grizzly, spring and jersey project and i have encountered:
Here is my current problem. I am working with the chat module and I'm
Currently working on a game, and is converting it to retina. I am using
I'm currently working on learning some game development with Java. I'm working on the
I'm currently working on a game engine in java, however I'm having preformance issues

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.