Where to put prototype extends?
-
I tried to use the code example from the docs:
Spawn.prototype.createWorkerCreep = function(name) { return this.createCreep([WORK, CARRY, MOVE], name); };
When I try to execute:
Game.spawns.Spawn1.createWorkerCreep('Worker1');
I get an error saying the function is not defined.
I put this as the first thing in my main module in the script section. Is this correct? If someone could enlighten me what I am doing wrong here, that'd be great.
Thanks.
-
Hmm, I tried a simple test and this works:
Spawn.prototype.test = function() { console.log("Hello world"); } Game.spawns.Spawn1.test();
Also, I use this to highlight my code (I hope it shows up correctly)
javascript
<some random code here>
Are you sure the prototype is included? insert a console line right after declaring the function for test purposes.
-
uh the snippet didn't show up correctly, just watch this link
https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting
-
Yeah I messed up the MD part and didn't find the edit button.
Interestingly it works when I put the call to the added prototype method in the script tab, but it doesn't work in the console.
-
I looked around in the forum and this seems to be a common problem. Not sure why to include a console at all if you can't it use to access your code.