Hey everyone I’m having some problems with Siege of Stonehold. The first time I wrote my code it said “missing : after if self.isReady(“cleave”)”.
I fixed the error and it still said the same thing. Does anyone know what is wrong?
Here is my code:
loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance < 10:
self.attack(enemy)
flag = self.findFlag("black")
if flag:
if flag.color is "black":
self.pickUpFlag(flag)
distance = self.distanceTo(enemy) :
if distance < 5:
if self.isReady("cleave") :
self.cleave(enemy)
self.attack(enemy)
Ok I hope bringing this topic back up isn’t offensive or a violation to the FAQ, but I don’t understand what you mean by I didn’t put an if statement after the second one. What do you mean by that?
There are technically no rules set on stone that disallow bumping old threads. It is just a good forum practice to not bump “dead” or inactive threads, but as long as you still need help or have something meaningful to add, it is not a dead thread at all. Well, I guess the “rule” would be to just use common sense.
Now, back to the topic.
Every time you work with the enemy variable, you should make sure its value is not empty (None/null). Around the 13th line in your first post’s code, you are trying to get the distance to the enemy using self.distanceTo(enemy), but you didn’t check if the enemy variable is not empty—it should be guarded by an if enemy: like you did earlier in your code.
Though, it is probably better to put together all the code that deals with the enemy inside a single if enemy:, as Adrian has suggested above.
Ok sort of got the second if statement, but now on line 19 it is not accepting what I put in.
Here’s the code:
loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance < 10:
self.attack(enemy)
flag = self.findFlag("black")
if flag:
if flag.color is "black":
self.pickUpFlag(flag)
if distance = self.distanceTo(enemy)(
if self.distance < 10:
if self.isReady("cleave"):
self.cleave(enemy)
self.attack(enemy)
The code you have posted is not indented (missing spaces in the beginning of the lines), can you please try to fix it or copy it from inside the game again?