While playing screeps I can't figure out how to attack an enemy. Here's what I tried.
I created my attacker creep:
Then when the first enemy came on the screen I tried running this command and it fails.
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.
Best How To :
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:
var attacker = Game.creeps.Attacker1;
var enemies= attacker.room.find(Game.HOSTILE_CREEPS);
- Creates a creep named
Attacker1 and assigns the object to a var named attacker
- Uses attacker's
find() function to find all enemies and assigns them to an array named enemies
- Moves your attacker to the first enemy in the array (
.attack() only works close range)
- Attacks the first enemy in the array of enemies