Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Assigning Variables to Enemies


It seems that when I assign variables to enemies, the first enemy I see gets the assignment, leaving the other ones untouchable. If I assign one enemy to enemy1, and then the other to enemy2, the first enemy will be “enemy1” and “enemy2”. If I assign more varaibels the first enemy in the line of sight will be enemy1, enemy2, enemy3…and so on.
Any way around this?


Could you pls post a screenshot of what is happening? Also what level are you on?


Try this. This makes it so you can assign a variable to the nth enemy.

enemy=enemies[0] #This finds the first enemy 
enemy1=enemies[1] #This finds the second enemy
enemy2=enemies[2] #This finds the third enemy. 



you can do this instead finding each enemy 1 by 1

var enemy = hero.findNearestEnemy();
while (enemy){


I can still only target one enemy to attack. My character never picks up that there are two.


Put the var enemy=hero.findNearestEnemy();, into a while (true){ } loop. It checks for an enemy every frame and attacks it.


i meant to put the while enemy inside of a while true loop, sorry if i confused you


Hey guys thanks for the help. This level has been solved. I ditched the loops and just told the character to do everything step by step and that worked.


Put [SOLVED] on the title so everyone can see.


I’m sure Enderlord meant:

    var enemy = hero.findNearestEnemy();
    while(enemy && > 0)

if the condition is only while(enemy) and the hero has a weak sword the result will be the message:
and the hero will freeze.