# Coded Orders Help

Right now, I have the troops summoned, but when I try to interpret the coordinates, I can’t seem to figure out how to convert the string into a number value.

``````// Read the message on the sign to determine which units to summon and where to place them.
// Check the guide for instructions on interpreting the orders.

var sign = hero.findByType("sign")[0];
var message = sign.message;

// Tip: parse the sign, then summon the units, then send each unit to the right position.
for (var i = 0; i < message.length; i += 5) {
var letter = message[i];
if (letter === "a") {
hero.summon("archer");
var x = message[i + 1] + message[i + 2];
var y = message[i + 3] + message[i + 4];
hero.command(hero.built[hero.built.length - 1], "move", {"x": x, "y": y});
} else if (letter === "s") {
hero.summon("soldier");
} else if (letter === "p") {
hero.summon("peasant");
} else if (letter === "g") {
hero.summon("griffin-rider");
}
}
``````

3 Likes

Hey @Greninja714 great question. I believe the issue with you code is actually explained in the error. It says that you need to have `{ x: (number), y: (number)}` instead of just `x: x, y: y` which means that you need to define what x is.

I believe that they have defined x and y, but x and y are defined as strings not numbers. The error says it should have type number not the string “14”.

I know what the problem is, but what should I do now? Is there a way to convert strings to numbers?

``````// Read the message on the sign to determine which units to summon and where to place them.
// Check the guide for instructions on interpreting the orders.

var sign = hero.findByType("sign")[0];
var message = sign.message;

// Tip: parse the sign, then summon the units, then send each unit to the right position.
for (var i = 0; i < message.length; i += 5) {
var letter = message[i];
if (letter === "a") {
hero.summon("archer");
var x = message[i + 1] + message[i + 2];
var y = message[i + 3] + message[i + 4];
hero.command(hero.built[hero.built.length - 1], "move", {"x": x, "y": y});
} else if (letter === "s") {
hero.summon("soldier");
} else if (letter === "p") {
hero.summon("peasant");
} else if (letter === "g") {
hero.summon("griffin-rider");
}
}
``````

Ok i figured it out just a simple built-in function did it! thanks for the help

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.