Forest Fire Dancing (help) CPP [SOLVED]

Edit: nevermind. I was over thinking it…
I keep getting errors. but frankly that is the least of my worries. I feel like I am just butchering this code. Making it more unusable the more attempts I put in. I was trying to back peddle to find a level more like it. Tracking items to get my character to move left and right. I either didn’t understand enough for it to click in my head or there is nothing close enough.
I get a lot of closing bracket for like 15 for line 3 or something weird like that. No matter how much I tinker with it. The error code just seems to get worse and worse! Sometimes I get close enough but then it starts requesting ; at the end of code that it is already there!

Edit: tiny update!(not current code)
Here was my current code.<---- scroll down for the cleaner updated version.

// In this level the evilstone is bad! Avoid them, walking the other direction.
int main() {
    while (true) {
        auto evilstone = hero.findNearestItem();
        if (evilstone) {
            auto pos = evilstone.pos;
            if (pos.x == 34) {     // == means "is equal to"
                // If the evilstone is on the left, go to the right side.
                hero.moveXY(46, 22);
            } else {
                // If the evilstone is on the right, go to the left side.
                if (pos.x == 46) {
                    hero.moveXY(40, 22);
                }
        } else {
            // If there's no evilstone, go to the middle.
            if (pos.x == 40) {
                hero.moveXY(34, 22);
        }
    }
    
    return 0;
}

Do keep in mind this is a work in progress on just trying to get my character to move properly past the original code in place.

Edit 3: I did a bit of clean-up. After a short cool down period. Which helped a lot. So for any fellow nubs out there. This may help. but still broken because I am not sure what to put for when the orb is none existant.

// In this level the evilstone is bad! Avoid them, walking the other direction.
int main() {
    while (true) {
        auto evilstone = hero.findNearestItem();
        if (evilstone) {
            auto pos = evilstone.pos;
            if (pos.x == 34) {     // == means "is equal to"
                // If the evilstone is on the left, go to the right side.
                hero.moveXY(46, 22);
                            } 
            else {
                // If the evilstone is on the right, go to the left side.
               if (evilstone) {
                   auto pos = evilstone.pos;
                if (pos.x == 46) {
                    hero.moveXY(34,  22);
                                 }
                 } 
            }
                     }
        else {
            // If there's no evilstone, go to the middle.
            if (evilstone) {
                auto pos = evilstone.pos;
            if (pos.x == null) {
                hero.moveXY(40, 22);
                             }
                         }
             }
                }
    return 0;
    }

Have you solved it then? Or are you still in need of assistance?
Danny

Yes. I was over thinking it. Answer was just taking away the last else and replace it with hero.move(xy)

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.