Level: Ogre Encampment


#1

We’re teaching if/else and a new style of game tactic in this one, so we’re most curious about the playability (how easy/difficult is it?). Let us know!


#2

Hi

Currently unplayable. (but I was able to open the chest with this code, it worked, but there’s some error)

I’ll be embarrassed if there is an if/else code example somewhere on the page, but I couldn’t find it.

I get “fix your code, unexpected token” and a red x on the line with my if statement.

here is my code
loop:
# Use if/else.
enemy = self.findNearestEnemy()
if enemy
self.attack(enemy)
self.attack(enemy)
else
self.attack(“Chest”)


#3

For anyone following me this code worked (note the colon [:] after the if condition and after the else)
(got the idea from the scenario after this one.)
loop:
# Use if/else.
enemy = self.findNearestEnemy()
if enemy:
self.attack(enemy)
self.attack(enemy)
else:
self.attack(“Chest”)


#4

BUG : Default code works

The Default Javascript Code worked for :stuck_out_tongue: I dint even have to attack the ogres btw, cause Tharin’s HP is 120 so he could withstand the damage until he opened the chest


#5

Looks like you came in with the longsword, which you get after doing this one. Did you do them out of order somehow, or did it give you the items in a buggy order?


#6

@nick I dont really remember when I unlocked the longsword, but as far as I remember I did play the campaign in order.


#7

I did not see the longsword when I first do this level but as I had a problem with the syntax, I looked at the Back to Back level without finishing the level then I had the longsword and the Sundial Wristwatch. It may be the same bug for DollarAkrhay.


#8

This mission is not unlocking for me, even though I just completed Back to Back(Javascript)

Any ideas why?


#9

Until we fix the strange bugs with unlocks not firing, you can try going to http://codecombat.com/play/forest?next=ogre-encampment to force it to let you play that one.


#10

I am having the same issue as well. I can’t play the next level, even though I have unlocked the previous level.


#11

on this one, at least for Python, remember that when you use loop:, all statements underneath are four spaces indented. Furthermore, when if/else is used, for example as a part of the loop, statements underneath if/else need to be indented an additional four spaces. So the correct code, with errors, i.e., “fix your code, unexpected token” looks like this for Ogre Encampment:

loop:

(4spaces) enemy = self.findNearestEnemy()
(4spaces) if enemy:
(8spaces)self.attack(enemy)
(8spaces)self.attack(enemy)
(4spaces)else:
(8spaces)self.attack(“Chest”)

Notice, there are two levels of 4 space indents. Sorry, this post area doesn’t show spaces correctly, it deletes them, so I wrote in the number of spaces at the beginning of each line.


#12

You can get your code to format properly by surrounding it in triple backticks and typing the programming language name. This:

[code]```python
enemy = self.findNearestEnemy()
if enemy:
self.attack(enemy)


becomes this:

```python
enemy = self.findNearestEnemy()
if enemy:
    self.attack(enemy)

#13

Guys
If you loop Self.attack(chest) it will work


#14

@malcom, i have been trying to get past this level for forever, it keeps on giving me “fix your code, unexpected token” even if i use the code you put out or anyone else! i don’t understand:(((


#15

ok, so i tried this but it says, "Line 2: ReferenceError: enemy is not defined"
loop:
enemy == self.findNearestEnemy()
if enemy:
self.attack(enemy)
self.attack(enemy)
else:
self.attack(“Chest”)


#16

First off:
Post your code as according to the FAQ.

Second off:
This “==” is used in comparison. For a variable, you only use one “=”


#17

Also, you need to indent after the loop, the if enemy, and the else statements.


#18

That’s why it needs to be posted according to the FAQ, otherwise, Indents don’t show. The code could be properly indented, but discourse won’t show it.


#19

omgosh thank you so much! i hated not being able to figure it out!


#20

Hey, It seems I have the exact code as the others on this thread, but i still keep dying! I’m not sure why! I did exactly what the instructions ask but I keep dying :confused: