[SOLVED] Help! Coded Orders

# 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.

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

# Tip: parse the sign, then summon the units, then send each unit to the right position.

So uhh . . . how do I parse the sign?

Lydia

What do you mean by parse the sign?

Is that all of your code as of right now?

Yes, that is all my code, I don’t know how to parse the sign, but the level requires me to parse it.
Lydia

this is the starter code. can you come back with some code that we can help you with

I don’t know how to parse it. That is why I am asking.
Lydia

To parse means to go over line by line, or character by character. Here it would involve using a for loop to go over the message, which is really just an array of single characters like this: “a”.

1 Like

To be honest I don’t even know what parse means but i assume it is this

summonTypes = {"a": "archer", "s": "soldier", "p": "peasant", "g": "griffin-rider", "P": "paladin", "A": "artillery"}

I did something like this

summonTypes = {"a": "archer", "s": "soldier", "p": "peasant", "g": "griffin-rider", "P": "paladin", "A": "artillery"}```

this is the summon types you use them in a function which will be put in a for-in-loop


sign = hero.findByType("sign")[0]
message = sign.message
summonTypes = {"a": "archer", "s": "soldier", "p": "peasant", "g": "griffin-rider", "P": "paladin", "A": "artillery"}
# Tip: parse the sign, then summon the units, then send each unit to the right position.
while True:
    for summonType in summonTypes:
        if summonType == "a":
            hero.summon("archer")
        if summonType == "s":
            hero.summon("soldier")
        if summonType == "p":
            hero.summon("peasant")
        if summonType == "g":
            hero.summon("griffin-rider")
        

Now my hero just keeps summoning soldiers, archers, griffin-riders, and peasants.
How do I parse the x y cordinates?
Lydia

This is not the correct thing to use

while True:
    for summonType in summonTypes:
        if summonType == "a":
            hero.summon("archer")
        if summonType == "s":
            hero.summon("soldier")
        if summonType == "p":
            hero.summon("peasant")
        if summonType == "g":
            hero.summon("griffin-rider")

Instead use this

def summonTroops(num, coorX, coorY):
    type = summonTypes[num]

You’ve got to parse the message, not the summonTypes. Remember the letters only come once every 5 characters in the message, so you’ll want a step of 5.
@Archipelago-Gold stop stealing other peoples code. I know that you and milton didn’t write that and I don’t need to prove it, you know it yourself.
If you want to use it yourself then fine, but don’t tell other people how to do it line by line too.

4 Likes

I still don’t get how to “parse” the message. Do I separate out the letters? If so, how do I do that?
Lydia
P.S. Sorry if I sound stupid.

2 Likes

Look you should type in the message things for artillery and paladins but just put continue

@milton.jinich I think you should let deadpool deal with this he has it under control

Well, as I said, message is just an array.
With an array you would do this:

for i in range(0, len(enemies)):
    enemy = enemies[i]

You can do the same for a string (that’s what this message is):

for i in range(0, len(message)):
    character = message[i]

That character would be something like “a”, or “9”.
Remember the structure of the message is:
TxxyyTxxyyTxxyy etc…
That means Type e.g. “a” for archer. XX for the x coord e.g. 45 and YY for the y coord e.g. 22.
So if you put in a step of 5 at the end of the for loop, you could go over the message only accessing the Type letters and you could base the position off that.

3 Likes

sign = hero.findByType("sign")[0]
message = sign.message
summonTypes = {"a": "archer", "s": "soldier", "p": "peasant", "g": "griffin-rider", "P": "paladin", "A": "artillery"}
# Tip: parse the sign, then summon the units, then send each unit to the right position.
for i in range(0, len(message)):
    character = message[i]
    if character == "a":
        hero.summon("archer")
    if character == "s":
        hero.summon("soldier")
    if character == "p":
        hero.summon("peasant")
    if character == "g":
        hero.summon("griffin-rider")
    if character == "p":
        pass
    if character == "A":
        pass

Now my hero just summons two of each. How do I figure out the x and y coordinate?
Lydia

try doing continue instead of pass

It just does the same thing.
Lydia