screepers / screeps-typescript-starter

Starter kit for TypeScript-based Screeps AI codes.
https://screepers.gitbook.io/screeps-typescript-starter/
The Unlicense
440 stars 315 forks source link

Strange Behavior .... #74

Closed tigum27 closed 6 years ago

tigum27 commented 6 years ago

Hi, Something is strange with the way screeps server run the first function in the main exported by webpack Seems like several loop instances is alternating the run ,each one with its own globals Example:

REPLACE THE FIRST FUNCTION IN THE MAIN FOR THIS MODIFIED ONE AND YOU WILL SEE WHAT I M TALKING ABOUT ...

/**/ (function(modules) { // webpackBootstrap /**/ // The module cache /**/ var installedModules = {}; /**/ /**/ // The require function /**/ function webpack_require(moduleId) { /**/ /**/ // Check if module is in cache /**/ if(installedModules[moduleId]) { /**/ return installedModules[moduleId].exports; /**/ } /**/ // Create a new module (and put it into the cache) /**/ var module = installedModules[moduleId] = { /**/ i: moduleId, /**/ l: false, /**/ exports: {} /**/ }; /**/ /**/ // Execute the module function /**/ modules[moduleId].call(module.exports, module, module.exports, webpack_require); /**/ /**/ // Flag the module as loaded /**/ module.l = true; /**/ /**/ // Return the exports of the module /**/ return module.exports; /**/ } /**/ /**/ /**/ // expose the modules object (webpack_modules) /**/ webpack_require.m = modules; /**/ /**/ // expose the module cache /**/ webpack_require.c = installedModules; /**/ /**/ // identity function for calling harmony imports with the correct context /**/ webpack_require.i = function(value) { return value; }; /**/ /**/ // define getter function for harmony exports /**/ webpack_require.d = function(exports, name, getter) { /**/ if(!webpack_require.o(exports, name)) { /**/ Object.defineProperty(exports, name, { /**/ configurable: false, /**/ enumerable: true, /**/ get: getter /**/ }); /**/ } /**/ }; /**/ /**/ // getDefaultExport function for compatibility with non-harmony modules /**/ webpack_require.n = function(module) { /**/ var getter = module && module.esModule ? /**/ function getDefault() { return module['default']; } : /**/ function getModuleExports() { return module; }; /**/ __webpack_require.d(getter, 'a', getter); /**/ return getter; /**/ }; /**/ /**/ // Object.prototype.hasOwnProperty.call /**/ webpack_require.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /**/ /**/ // webpack_public_path /**/ webpack_require.p = ""; /**/ /**/ // Load entry module and return exports /**/ //return webpack_require(webpack_require.s = 21); // CHANGE THE ENTRY POINT FOR THIS LOOP

         global.var1=0;
         modules.loop = function(){
            global.var1++;
            console.log("Global Var ->"+global.var1);

        };
        return modules;

/**/ })

Look at Console messages .. seems like different loop functions alternating ...

resir014 commented 6 years ago

Hey @tigum27, could you try using the updated starter kit at the v3.0 branch? We've recently been working on a new version of the starter kit from the ground up, with Rollup as its new module bundler.

Should work just fine, and even better, it doesn't emit a long boilerplate code like Webpack did.

resir014 commented 6 years ago

Closing this due to lack of activity. Feel free to create a new issue/reopen this issue should this issue still persist.