While playing screeps I can't figure out how to attack an enemy. Here's what I tried.
I created my attacker creep:
Game.spawns.Spawn1.createCreep(['attack','move'],'Attacker1');
Then when the first enemy came on the screen I tried running this command and it fails.
Game.creeps.Attacker1.attack("Player 3");
What is the correct syntax for the enemies?
Edit: Adding the link for the documentation for accessing objects in the game. http://screeps.com/docs/Creep.php
"Player 3" is the name of the enemies. I need to some how target the enemy and fight them.
I'm not sure why you're getting down voted so much, you've put plenty of info on here! It looks like you're close to getting it! If you read the docs you linked to you'll see that it says attack(target)
and that target is an object. Currently you're passing attack()
a string, "Player 3"
. In order for the attack function to actually target something you need to give it an object. Try something like this:
Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.MOVE],'Attacker1');
var attacker = Game.creeps.Attacker1;
var enemies= attacker.room.find(Game.HOSTILE_CREEPS);
attacker.moveTo(enemies[0]);
attacker.attack(enemies[0]);
This code:
Attacker1
and assigns the object to a var named attackerfind()
function to find all enemies and assigns them to an array named enemies.attack()
only works close range)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With