Navigation

    forum

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    1. Home
    2. Wheasle
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups
    • Blog

    Wheasle

    @Wheasle

    2
    Posts
    785
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Wheasle Follow

    Posts made by Wheasle

    • RE: [SOLVED] room prototype stats problem reading length of hostiles found

      Hi KnackwurstBagel,

      Thanks for this explanation, this has been very detailed and helpful.  I've seen a few of the prototypes around and always tried treating them like a function and therefore could never get them working.  Thanks for steering me in the right direction.

      Cheers.

      posted in Help
      Wheasle
    • RE: [SOLVED] room prototype stats problem reading length of hostiles found

      Hi, i'm extremely new to javascript and therefore am probably asking a stupid question, but can you explain how you would call your function from within main?

      So far, I've created a module called 'logs.test' and copied your code into this module.

      from within main I can't seem to work out how to successfully call it and was hoping you could help?

      All I see within the console is "Testing this function: undefined"

       

      [main]

      var Test = require('logs.test');

      module.exports.loop = function () {

          console.log('Testing this function: ' + Test());

      ...

      }

      [/main]

       

      [logs.test]

      module.exports = function(){
      Room.prototype.stats = function(){

      var foes = this.find(FIND_HOSTILE_CREEPS, {
      filter: function(object) {
      return object.getActiveBodyparts(ATTACK) == 0;
      }
      });

      if (foes.length > 0){
      return {
      hostiles: foes,
      numHostiles: foes.length,
      hostileUser: foes[0].owner.username
      };
      } else {
      return {
      hostiles: foes,
      numHostiles: 0,
      hostileUser: undefined
      }
      }
      }
      };

      [/logs.test]

      posted in Help
      Wheasle