# ml-game-loop

> Simple game loop

Latest version **0.5.3** (published 2015-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install ml-game-loop
pnpm add ml-game-loop
yarn add ml-game-loop
bun add ml-game-loop
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.3 |
| Published | 2015-09-04 |
| First published | 2015-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dariusz Półtorak |
| Maintainers | dariuszp |
| Keywords | game, loop, madman, labs |

## Links

- npm: https://www.npmjs.com/package/ml-game-loop
- Repository: https://github.com/madman-labs/game-server-loop
- Issues: https://github.com/madman-labs/game-server-loop/issues
- npm.io page: https://npm.io/package/ml-game-loop

## Recent versions

- 0.5.3 (latest) — 2015-09-04
- 0.5.2 — 2015-03-28
- 0.5.1 — 2015-03-28
- 0.5.0 — 2015-03-28
- 0.1.0 — 2015-03-26

## README

# game-server-loop

Simple game loop that allow queue of sync instructions.

## Installation

```
npm install ml-game-loop --save
```

## Usage

```JavaScript
'use strict';

var GameLoop = require('ml-game-loop');

var loop = new GameLoop(),
    i = 0;

// this will run every time loop is started
// every time will have counter instead writing new line
loop.add(function (time, diff) {
    // time is current timestamp with milliseconds
    // diff is a time that passed since last execution
    process.stdout.write("\r every time!" + String(i++));
});

// this will run every after at least 100ms pass but always after previous callback
loop.throttle(100, function (time, diff) {
    process.stdout.write("\n* EVERY 100 MS !!!!!! *\n");
});

// as above but after 1000ms and it is named "every-second"
loop.throttle(1000, function (time, diff) {
    process.stdout.write("\n*** ALWAYS AFTER 1 SECOND - 1000 MS !!!!!! ***\n");
}, 'every-second');

/*
 * start loop, remember that callback always run in same order so if all three callbacks are valid (and all are on first start)
 * you will see three sentences
 * - every time! X
 * - * EVERY 100 MS !!!!!! *
 * - *** ALWAYS AFTER 1 SECOND - 1000 MS !!!!!! ***
 * ALWAYS in same order
 */
loop.start();

setTimeout(function () {
    // this will pause the loop after 5 seconds
    loop.pause();
    // this will stop execution of "every-second" callback, use loop.enable('every-second') to resume it
    loop.disable('every-second');
}, 5000);

setTimeout(function () {
    // this will pause the loop after 7 seconds, 2 seconds after pause
    loop.resume();
}, 7000);

setTimeout(function () {
    // this will stop the program after 10 seconds of working
    loop.stop();
}, 10000);
```

### Have fun!

---
_Source: https://npm.io/package/ml-game-loop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
