Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Forest Fire Dancing Problem

#1

My codes don’t seem to work.

Can you have a look at them and see whats wrong?

while True:
evilstone = hero.findNearestItem()
if evilstone:
pos = evilstone.pos
if pos.x == 34:
hero.moveXY(46, 22)

    if pos.x == 45:
        hero.moveXY(35, 22)
        
        
else:
    hero.moveXY(40, 22)

Isn’t this supposed to work?

#2

@iwchoikr Your code has the potential to be right. However are you sure its doing what you expect?

Add the below code and ask what does this statement show as you run through the loop?
hero.say(evilstone.pos.x)

Also I had to format your code with tabs. I assume this is what you are looking at in the editor?


while True:
	evilstone = hero.findNearestItem()

	if evilstone:
		pos = evilstone.pos
		if pos.x == 34:
			hero.moveXY(46, 22)
		if pos.x == 45:
			hero.moveXY(35, 22)
	else:
		hero.moveXY(40, 22)
#4

" if pos.x == 34:" doesn’t seem to work.

#5

The original code is written in Python, but it looks like you might be writing in JavaScript. The two languages use different syntax, a type of format with rules. You need to follow the correct syntax for the language you are writing in.

Python:
if pos.x == 34:

JavaScript
if (pos.x == 34) {

If you need specific help, post your code and someone can walk you through it. Below is a link that will help you post your code properly so we can help.

#6

Here’s my current code (basically used their codes to see if it will fix my problem since I didn’t know they were using Python ._.

while True:
	evilstone = hero.findNearestItem()

	if evilstone:
		pos = evilstone.pos
		if pos.x == 34:
			hero.moveXY(46, 22)
		if pos.x == 45:
			hero.moveXY(35, 22)
	else:
		hero.moveXY(40, 22)
#7

My first question, do you want to complete this in Python or translate it back to JavaScript?

Second, do you know how to find the X, Y coordinates on your map?

While the code has the correct setup, there is one coordinate that doesn’t meet the level requirements.

#8

Wait… how do you switch from Javascript to Python? See, I have a classroom acc so…what do I do?

#9

Also, I do know how to check X, Y coordinates.

#10

Not sure if the classroom version allows you to switch. The non-classroom lets you pick which language you want to work with when selecting the hero. Go to the Game Menu at the top and change hero. At the bottom, I have the option to change language.

#11

If you can’t switch to Python, go ahead and click the Restart at the top right corner to get you back to the base code for JavaScript. We can go from there. You can use the same concept that is shown in the Python code, but you need to translate it into JavaScript.

#12

This is what I currently have for right now… took me like… 5 hours but, I think I’m on the right track.

// In this level the evilstone is bad! Avoid them, walking the other direction.
while (true) 
    var evilstone = hero.findNearestItem();
    if (evilstone) 
        var pos = evilstone.pos;
        if (pos.x == 34) (pos.y == 22); 
            hero.moveXY(46, 22);
        
         if (evilstone) {
                 var pos = evilstone.pos;
                 if (gem.pos.x == 46) (pos.y == 22);
                 hero.moveXY(34, 22)  ;
        }
          else {
              hero.moveXY(40, 22);
          }

#13

If not, I’ll restart it but I want you to get an expert look at it before I make any changes.

May 4th 2019: Ok, i’ll make those revisions. If I’ve questions, i’ll ask you. (PS: since i’ve reached my limit, i’m gonna be communicating through here).

May 4th 2019: I did those revisions but it’s saying there is an error

#14

You are getting there. A few details to work out. You are missing several of the brackets {} with the if statements. Another thing, the pos.y == 22 check is not needed at all.

The second check can be simplified. You are still checking for the evilstone again, when you don’t need to in this one. Just check the pos.x position like the first one, but the right side.

if (evilstone) { // not needed
                 var pos = evilstone.pos;  // not needed
                 if (gem.pos.x == 46) (pos.y == 22); // only need if (pos.x == 46){
                 hero.moveXY(34, 22)  ;
}