Stuck on Sesame Path - assistance please!


#1

Hello all,

I’m stuck on Sesame Path and I’m totally unsure as to how to proceed even after reading the Tips many times. I also know there was a question about this same level, but the help advice was to check the tips included on the level. This was enough to help the poster, but unfortunately I’m still struggling.

There is tons of code pre-included in the example and I’m just not sure what to add or modify.
I see that I’m supposed to check all directions with isPathClear, but that check already seems to be written in the supplied code. What am I missing? Many thanks!!

// Say "Open Sesame" and a door will open.
// Only doors near you will hear you.
// There is only one route without forks.
// The distance between each point is 24m.

var sesame = "Open Sesame";
var distance = 24;
var previous = "";

while (true) {
    hero.say(sesame);
    // Check each direction to see if the path is clear.
    // Be sure to check and record your previous direction!
    // Up
    if(hero.isPathClear(hero.pos, hero.pos.add({x:0, y:24})) && previous != "down") {
        hero.moveXY(hero.pos.x, hero.pos.y + 24);
        previous = "up";
    }
    // Down
    else if(hero.isPathClear(hero.pos, hero.pos.add({x:0, y:-24})) && previous != "up") {
        hero.moveXY(hero.pos.x, hero.pos.y - 24);
        previous = "down";
    }
    // Left
    else if(hero.isPathClear(hero.pos, hero.pos.add({x:-24, y:0})) && previous != "right") {
        hero.moveXY(hero.pos.x - 24, hero.pos.y);
        previous = "left";
    }
    // Right
    else if(hero.isPathClear(hero.pos, hero.pos.add({x:24, y:0})) && previous != "left") {
        hero.moveXY(hero.pos.x + 24, hero.pos.y);
        previous = "right";
    }
}

#2

I think the problem is with the use of hero.pos.add(): Some time ago a player implemented the use of cloning Vectors when using Vector instance methods within the game code, based on API protection hacks; but now with a new code interpreter I don’t think the old API protection is in use anymore and this might be causing problems, as hero.pos is being mutated and causing weird teleportation.

I tested the code and you could get around the issue by replacing hero.pos.add with hero.pos.copy().add, though that just gives you the correct solution…so I think the level sample code needs to be updated. :wink:


#3

If problem in add - use this

    up = {'x':self.pos.x, 'y':self.pos.y + distance}
    down = {'x':self.pos.x, 'y':self.pos.y - distance}
    right = {'x':self.pos.x + distance, 'y':self.pos.y}
    left = {'x':self.pos.x - distance, 'y':self.pos.y}

#4

Many thanks trotod and RobAnybody.
Inserting .copy() worked like a charm!
All the best and thanks again!


#5

I had passed it in Python.

Say “Open Sesame” and a door will open.

Only doors near you will hear you.

There is only one route without forks.

The distance between each point is 24m.

sesame = "Open Sesame"
distance = 24
previous = “”

while True:
item = hero.findNearest(hero.findItems())
hero.say(sesame)
up =hero.isPathClear(hero.pos, {‘x’:hero.pos.x,‘y’:hero.pos.y+24})
down = hero.isPathClear(hero.pos, {‘x’:hero.pos.x,‘y’:hero.pos.y-24})
left =hero.isPathClear(hero.pos, {‘x’:hero.pos.x-24,‘y’:hero.pos.y})
right =hero.isPathClear(hero.pos, {‘x’:hero.pos.x+24,‘y’:hero.pos.y})

if  up  and previous != "down":
    hero.moveXY(hero.pos.x, hero.pos.y+24)
    previous = "up"

if  down and previous !="up":
    hero.moveXY(hero.pos.x, hero.pos.y-24)
    previous ="down"
hero.say(sesame)

    
if  right and previous !="left" :
    hero.moveXY(hero.pos.x+24, hero.pos.y)
    previous ="right"
if  left and previous !="right":
    hero.moveXY(hero.pos.x-24, hero.pos.y)  
    previous ="left"




# Check each direction to see if the path is clear.
# Be sure to check and record your previous direction!
# Up

# Down

# Left

# Right

#6

i were the smme problem with you! your problem had solved?