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 6081571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:11:28+00:00 2026-05-23T11:11:28+00:00

Good day, I am playing with JS.Class right now and I’m making a text-based

  • 0

Good day,

I am playing with JS.Class right now and I’m making a text-based game. For now, it is executed in a browser but eventually,
it will be executed in a Node.js environment managing sockets and ANSI colors supports for players using a telnet-like client.

I have created a few classes and one of them define Characters (which is either a real player or an in-game character).

For a real player, the code to create a new one looks like this: new Character( "userId", { /* player's options/settings/parameters here*/ }, socket );

Example:

new Character( "000001", {
    "Name" : "Cybrix",
    "Zone" : "000001-000003",
    "Stealth" : false,
    "Fighting" : false,
    "Blind" : false,
    "Sleeping" : false
}, socket );

More than often, the in-game characters should have differents and uniques methods that I use to simulate an event-like behavior.

Example:

new Character( "000001", {
    "Name" : "Large Dragon Boss",
    "Zone" : "000001-000003",
    "Stealth" : false,
    "Fighting" : false,
    "Blind" : false,
    "Sleeping" : true,
    "onArrive" : function( target ) {
        /* do something unique to this character. Eg: attack target */
    }
}, undefined );

The question:

I would like to find an efficient way to load all the “uniques” in-game characters on demand (which happens usually when a new area is loaded).
that will support functions. I really thought about using AJAX but that would be invalid JSON format.

Any tips on how to achieve this or what should I change in my “game” design to achieve this?

I, for sure, need a solution that will both work in my browser and can be ported nicely to Node.js.

Thank you!

(PS: Sorry for my very specific problem that might not help anyone else)
(PS 2: I don’t know how what question to use in the Title)

  • 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-23T11:11:28+00:00Added an answer on May 23, 2026 at 11:11 am

    Can these characters be split into types of characters. You could have your character types inherit from Character and each implement their own onArrive method. Something like:

    function Dude(){};
    Dude.prototype = new Character         // inherit from character
    Dude.prototoype.onArrive = function(){
      // do some stuff
    }
    

    And so on.

    You can’t have a function defined in your JSON returned from a server, nor do you want to. That would be too tightly coupled. Just define object prototypes that inherit and create character types that have the appropriate ‘features’ (or behaviour)

    Additional

    I’m a bit confused as to what you’re looking for, but let me take another stab. IF you have some data being exchanged between a few servers, (character data) you want to be able to instantiate objects of a certain type. Assuming this data knows its type (ie add this as a property to the character JSON) then you can instantiate an object of any type. Using the above prototype declarations, you can create as many types of Character that you want. You could then instantiate this type through some factory method. For instance

    var Factory = {
      new: function(attrs){
        return new classes[attrs.type](attrs);
      }
    };
    
    var classes = {
      dude: Dude,
      another: Another,
      blah: Lah,
    };
    

    Assuming that you’ve defined Dude, Another, Lah as other prototypes of Character and they each implement some onAdd method (or just use the default defined in Character. Then you can use it like so:

    character = Factory.new({
      type: 'dude',
      "Name" : "Cybrix",
      "Zone" : "000001-000003",
      "Stealth" : false,
      "Fighting" : false,
      "Blind" : false,
      "Sleeping" : false
    });
    
    character.onAdd();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I am having an issue trying to get the Text on a
Good day everyone. I have a question about making and using derived classes of
Good day, I was playing with the example found here on SO: PHP Socket
Good day! How is the confirmation for deletion usually done in Web-based applications? I
Good day! I tried using JSTL in java but there's an error: exception javax.servlet.ServletException:
Good day Im trying to implement a read/write privilege in a folder but no
Good day, I have recently started playing with RingoJS along with Stick middleware and
Good day! I'm learning how to record video with MediaRecorder but recorded video is
Good day! I am planning to create a flash game on my own. Is
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We

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.