Hi Wheasle, Sorry for the delay in responce. The function I wrote is to be used as a prototype, as such its not meant to be called directly. The way you would use my code is by doing something like
[main]
require('logs.test')();
...
var stats = Game.spawns['Spawn1'].room.stats();
[/main]
The first line I am not assigning to a variable because the import is a function that needs to run immediately in order to register my prototype
A prototype is a way we can add functionality to objects we did not make. The game has a room object , all objects have prototypes, the code I wrote registers my custom function with the room object in order to create a new method called stats in this particular case. What it does is create a new object for you which has usefull information about your current attacker, in this format:
{
hostiles: foes,
numHostiles: foes.length,
hostileUser: foes[0].owner.username
};
So the idea here by doing something like var stats = Game.spawns['Spawn1'].room.stats(); is we get a new object called stats with three fields populated. Lets say we have one attacker in your room and its SomeUser, and that person has 5 of their attacking creeps in your room:
stats.hostiles would be an array of the 5 creeps your enemy has in your room (from what I remember, I havent played in a week)
stats.numHostiles would be 5
status.hostileUser would be 'SomeUser'
Your script now knows that SomeUser has 5 of their creeps with attack body parts inside your room.
I don't know how well my code works yet, just that its not throwing any errors, I havent had time to check. I hope that made some sence. I recomend searching for videos on youtube on the subject of prototypes, there are many good ones out there that explain it well.