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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:32:43+00:00 2026-06-06T12:32:43+00:00

Client + Server are both written in Javascript. I don’t have a master game

  • 0

Client + Server are both written in Javascript. I don’t have a master game loop because combat occurs sparingly and there is nothing else in the game that requires a loop. When two players initiate combat, they go into an auto-attack loop like this:

if ( combat key is pressed ) {

    check a bunch of stuff;
    setTimeout( combatLoop(); 5000 );

}

combatLoop = function() {

    attack(player1,player2);

    var loop = setTimeout( combatLoop(); 5000 );

    if ( skill variable == 1 ) { clearTimeout(loop); skill(); }

}

So, the combatLoop function gets called over and over again every 5 secs. The attack function handles what happens when the two input players attack each other. If players uses a skill, clearTimeout is used to get out of the loop, and the relevant skill() function is called. The skill function may or may not call combatLoop again.

Question 1

I am very new to Javascript, and I was wondering if you guys see any major flaw with doing it this way?

Question 2

I haven’t seen any similar examples of what I am trying to do, so I kinda hack the skill button part together. Is it “wrong” to make the combat loop “listen” to skill button presses this way (skill button press => set skill variable = 1) and clear the main loop using a clearTimeout? So, skill gets execute during the next attack (not in between attacks), which is fine by me. No idea what the industrial standard is. :p

  • 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-06T12:32:46+00:00Added an answer on June 6, 2026 at 12:32 pm

    You could do this, although I’m not a big fan of setInterval():

    if (keypressed) { //change this to a proper event handler ;)
      Engine.combatStart();
    }
    
    var Engine = {
      combatTimer: null, //timer var
      combatStart: function() {
        Engine.combatTimer = setTimeout(Engine.combatLogic, 5000);
      },
      combatLogic: function() {
        //calculate attacks etc...
    
        if (skill === 1) {
          clearTimeout(Engine.combatTimer);
          skill();
        }
    
        Engine.combatTimer = setTimeout(Engine.combatLogic, 5000);
      }
    };
    

    You can also:

    document.addEventListener("keypress", function(e) {
        if (e.keyCode === XX) {
             clearTimeout(Engine.combatTimer);
             skill()            
        }        
    });
    

    So you listen for a keypress, replace XX with the keycode for the skill key – then clear the timeout loop… :/

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

Sidebar

Related Questions

I have written a server and a client both as separate apps. They communicate
I have a client-server system, both sides written by me, and I would like
I have written a small client server socket application. It is a proof of
I have written a game in PlayN, which has to communicate with a JavaEE-Server
I'm using WCF in communication between a server and client (both written in C#).
I have written a Java server for remote storage (an iSCSI Target). The client
I have two utilities written in C++, TCP/IP server and client that I have
I have written an async UDP client to talk to a server at my
I've written both a WCF client and a remote internet WCF server. The remote
I have a very simple server written in C and an equally simple client

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.