[SOLVED] Wandering Souls Cannot Define a Variable


#1

@Bryukh @Serg @nick

So I noticed after I defeated Wandering Souls in Sarven Desert that if you define the distance variable first, the hero will just stand there and never pick up the lightstone.

For example:

        var item = items[itemIndex];
        // While the distance greater than 2:
        while (hero.distanceTo(item) > 2) {
            hero.moveXY(item.pos.x, item.pos.y);
        }

The code works and the hero collects the lightstone and I finish the level.

But, instead of defining distanceTo inside the while loop, I tried to define it as a variable and in theory, it should work the same. Here is the code:

      var item = items[itemIndex];
        var distance = hero.distanceTo(item);
        // While the distance greater than 2:
        while (distance > 2) {
            hero.moveXY(item.pos.x, item.pos.y);
        }

As you can see, I only created a variable distance, and used that in the while loop, however, my hero struggles to get the lightstone. This is a bug.


#2

By setting the distance before entering the while loop, the distance variable will never update again.

So let’s say the first Lightstone is 30 units away, you set the variable to 30, and you move towards it. The light stone moves away, but the variable says it’s still 30 units away. So you move to it again… Repeat 2-3 times before you can collect the lightstone… BUT!

The variable says you’re still 30 units away, so you’re stuck in the loop trying to move to the item’s position without ever actually updating your variable.

If you wanted it to work your way, you’d do this:

distance = hero.distanceTo(item) # Set the variable to start
while distance > 5: # Get caught in this while-loop
    # Try to take the item.
    hero.moveXY(item.pos.x, item.pos.y) # Move to the item
    distance = hero.distanceTo(item) # Update the variable

#3

Okay, Thanks! Now I get it. Even a Regular can’t be perfect :smile: