Help with Gems or Death level? (Ch. 2 lvl. 4) SOLVED

It keeps telling me I have errors in my code when everything works perfectly. Is there something I should be doing specifically for it to register as perfect?
Full code for the level I wrote out:

# != means "is not equal to".
if 2 + 2 = 4:
	self.moveXY(25, 15)  # Move to the second gem.

A quick suggestion would be to try and see whats working and whats not. Are you getting an error code? You also need to format your code correctly. Check the FAQ.I need help with my code! It could be your indents that. Did you add those “/” before “#” sorta a java script python mix there? When you get stuck also try copying what you have so you don’t lose it if you want to come back and then reload the level. Try it again with small changes, try and see whats working and whats not.

Helo, Maximus, and welcome. Please format your code according to the FAQ.

Your problem is in the line if 2 + 2 = 4:. If you notice, you only have one = sign, when the comparison sign is ==.

I used the “/” so that it did not format my text when I pasted it into this box. I am getting an error on lines 16-18 where I’ve written:
15 /# < means “is less than”.
16 if 2 + 0 < 4:
17 enemy = self.findNearestEnemy()
18 self.attack(enemy)
where on line 18 I get the error message “Fix your code: assigning to rvalue” when I see nothing wrong with it, and it runs fine.

I’ve solved it. I don’t know what the problem was, but I restarted and did everything exactly the same and it worked fine. Thanks for the help.

“assigning to rvalue” usually, means something like: “5 = 4” you are trying to use something that belongs on the right side of the assignment (rvalue) on the left side (where a variable name should go). Usually happens in if statement, when you meant “if 5 == 4” or “if 5 != 4” (“5 == 4” may look silly, but on this level it is a way to stop the “true” condition of an if statement from being run.)

It may also happen when you accidentally write: a + b = c (since “a+b” returns a number, say “5” for example, it then is like I mentioned above “5 =” . . . the “number” is on the left when numbers belong on the right.)

Not sure what was causing it in your case, but somewhere was something like that.

1 Like