Haris
1
return; //Commented out to stop infinite loop.
return; //Commented out to stop infinite loop.
var summonTypes = ['archer', 'soldier'];
function summonTroops() {
if (hero.gold >= hero.costOf(summonTypes)) {
hero.summon(summonTypes);
}
}
function commandTroops() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (friend.type == "archer") {
commandArcher(friend);
}
if (friend.type == "soldier") {
commandSoldier(friend);
}
if (friend.type == "peasant") {
commandPeasant(friend);
}
}
}
function commandArcher(archer) {
var enemy = hero.findNearestEnemy();
if (enemy) {
while (enemy.health > 0) {
hero.command(archer, "attack", enemy);
}
}
else {
hero.command(archer, 'move', hero.pos);
}
}
function commandSoldier(soldier) {
var enemy = hero.findNearestEnemy();
if (enemy) {
while (enemy.health > 0) {
hero.command(soldier, "attack", enemy);
}
}
else {
hero.command(soldier, "move", enemy);
}
}
function commandPeasant(peasant) {
var item = hero.findNearestItem();
while (item){
hero.command(peasant, "move", item.pos);
}
}
function collect() {
var item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
}
commandTroops();
while(true) {
collect();
}
as u can see.
deleate this lol
try to make less units as well…
UR PC IS GONNA GET JAMMED
Haris
3
already still doesn’t work.
Aya
4
I agree with ritic, how about you do only griffins, because what you have is a bit too much, the level doesn’t need all of this.
Also, do you want to command your troops only once or continuously?
Haris
6
var summonTypes = ['archer', 'soldier'];
function summonTroops() {
var type = summonTypes[hero.built.length % summonTypes.length];
if (hero.gold > hero.costOf(type)) {
hero.summon(type);
}
}
function commandTroops() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (friend.type == "archer") {
commandArcher(friend);
}
if (friend.type == "soldier") {
commandSoldier(friend);
}
if (friend.type == "peasant") {
commandPeasant(friend);
}
}
}
function commandArcher(archer) {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(archer, "attack", enemy);
}
else {
hero.command(archer, 'move', hero.pos);
}
}
function commandSoldier(soldier) {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(soldier, "attack", enemy);
}
else {
hero.command(soldier, "move", hero.pos);
}
}
function commandPeasant(peasant) {
var item = hero.findNearestItem();
if (item){
hero.command(peasant, "move", item.pos);
}
}
function collect() {
var item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
}
while(true) {
collect();
summonTroops();
commandTroops();
}
Haris
8
it work well but i get error code has infinite loop or code slow
Aya
9
Basically do this:
- Make a function where you find the peasant and command it to collect coins
- Make another function for summoning griffins
- Make the last function for commanding the griffins
- Make a while-true loop calling these three functions
And the error of infinite loop didn’t appear for me when i ran your code
summon hmmm
what can u summon
the one that costs the most
Haris
13
i have boss star 2 20 charac
Haris
14
hey why can i just do summon troops function method
?
Aya
15
That’s fine, you can use it, it was just a suggestion
1 Like
Aya
18
New code please? (20chars)
Haris
19
here i don’t need to reset the whole code i just get the error
var pos = [];
pos[0] = {'x': 23, 'y': 42};
pos[1] = {'x': 24, 'y': 31};
var summonTypes = ['archer', 'soldier'];
function summonTroops() {
var type = summonTypes[hero.built.length % summonTypes.length];
if (hero.gold > hero.costOf(type)) {
hero.summon(type);
}
}
function soldier() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (friend.type == "soldier") {
commandSoldier(friend);
}
}
}
function archer() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (friend.type == "archer") {
commandArcher(friend);
}
}
}
function commandArcher(archer) {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(archer, "attack", enemy);
}
else {
hero.command(archer, 'move', {'x': 24, 'y': 36});
}
}
function peasant() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i ++) {
var friend = friends[i];
if (friend.type == "peasant") {
commandPeasant(friend);
}
}
}
function commandSoldier(soldier) {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(soldier, "attack", enemy);
}
else {
hero.command(soldier, "move", {'x': 24, 'y': 29});
}
}
function commandPeasant(peasant) {
var item = hero.findNearestItem();
if (item){
hero.command(peasant, "move", item.pos);
}
}
function collect() {
var item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
}
function all() {
peasant();
soldier();
archer();
}
while(true) {
collect();
summonTroops();
all();
}
Aya
20
where do you get the error?