[Adventurer] Three-step Password


#1

The Mountain level Three-step Password is ready for playtesting!

The second level in the series of levels about str.split(sep) method.


#2

@Bryukh it looks like in the Python code on line 16 index = friend.index; there is a semi-colon? (removed in the patch)

completed the level without issue.

Added LUA patch


#3

Thanks. Usually, I write JS code and then convert it to PY. So those artifacts (:wink: are possible :slight_smile:


#4

what am I not following here. Is the index they get supposed to tell me what index to call in the array? Am I storing them in the array wrong?

# Find the password for the gates and defeat the ogres.

# Get the secret message.
hero.moveXY(52, 50)
friend = hero.findNearest(hero.findFriends())
message = friend.message

# Get the separator symbol.
hero.moveXY(66, 34)
friend = hero.findNearest(hero.findFriends())
separator = friend.separator

# Get the index.
hero.moveXY(52, 18)
friend = hero.findNearest(hero.findFriends())
index = friend.index

# Move to the gates.
hero.moveXY(44, 34)
# Split the message with the separator to get an array:
wordsArray = message;separator;index

words = wordsArray.split(";")
# Get the password from the array of words by the index:
password = words[0]
# Say the password:
hero.say(password)

# Defeat the ogres:
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

#5

What are you trying to do here?


#6

trying to put the messages into the array, if I put quotes it just puts the string in. Am I supposed to be using append or something? I thought the point was to use the split method somehow. Maybe I am confused.


#7

Have you played levels before that? About arrays, strings? Also there is one more with demonstration of split usage.

message;separator;index – it’s something weird.
You have a message - split it and you’ll get words.


#8

alright, so I feel dumb, that was pretty obvious instructions. use the separator as the separator…sorry for dumb question.


#9

I can’t figure out what is wrong. Here is my code:

# Find the password for the gates and defeat the ogres.

# Get the secret message.
hero.moveXY(52, 50)
friend = hero.findNearest(hero.findFriends())
message = friend.message

# Get the separator symbol.
hero.moveXY(66, 34)
friend = hero.findNearest(hero.findFriends())
separator = friend.separator

# Get the index.
hero.moveXY(52, 18)
friend = hero.findNearest(hero.findFriends())
index = friend.index

# Move to the gates.
hero.moveXY(44, 34)
# Split the message with the separator to get an array:
words = message.split("separator")
# Get the password from the array of words by the index:
password = words[index]
# Say the password:
hero.say(password)

# Defeat the ogres:
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

At line 25 it tells me that say’s argument message should have type string, but got null.


#10

Never mind…all I had to do was remove the quotes from line 21, then I beat the level. Sorry for disturbing anyone.


#11

You wrapped seperator in double quotes


#12

Yeah, I mentioned that…


#13

Hey you think you guys could help me with this website im new to it?


#14

What exactly is it that you need help with? It’s a board where people help each other with their code. Feel free to poke around and see how it works.


#15

thanks dude!!!


#16

Make sure to format your code properly using the format code button, and to never post final solutions on this forum. If you need any help, i will be there to guide you. You can always contact me at my email:
777brandonreyes@gmail.com