This Viking is really lost... -- Need help on level Lost Viking


#1

There are no errors but I can’t get my character to SWITCH somehow. What should I change?

Source code:

// You MUST click on the HELP button to see a detailed description of this level!

// The raven will tell you what to use for your maze parameters!

var SLIDE = 10;
var SWITCH = 7;
var SKIP = 11;
// How many sideSteps north of the Red X you've taken.
var sideSteps = 1;

// How many steps east of the Red X you've taken.
var steps = 1;

// Multiply this with steps to determine your X coordinate. DON'T CHANGE THIS!
var X_PACE_LENGTH = 4;

// Multiply this with sideSteps to determine your Y coordinate. DON'T CHANGE THIS!
var Y_PACE_LENGTH = 6;

var modSWITCH = steps % (SWITCH - 1);
var modSKIP = steps % (SKIP - 1);
var s = 1;
// The maze is 35 steps along the X axis.
while(steps <= 35) {

    // Take the next step:
    this.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH);
    
    // Increment steps and sideSteps as appropriate, taking into account the special rules.
    if (modSWITCH === 0 && this.pos.x > 6) {
        s = -s;
    } else if (modSKIP === 0 && this.pos.x > 6) {
        sideSteps += s;
    } else if (sideSteps < 1) {
        sideSteps = 10; 
    } else if (sideSteps > 10) {
        sideSteps = 1;
    }
    steps++;
    sideSteps += s;
}

#2

I’m by no means an expert, but as far as I can tell you’re not updating the value of modSWITCH in the while loop. You’re setting the value of it when you first create it, then just leaving it as is.


#3

Please help me on lost viking. This is my code:

You MUST click on the HELP button to see a detailed description of this level!

The raven will tell you what to use for your maze parameters!

How many sideSteps north of the Red X you’ve taken.

sideSteps = 1

How many steps east of the Red X you’ve taken.

steps = 1

Multiply this with steps to determine your X coordinate. DON’T CHANGE THIS!

X_PACE_LENGTH = 4

Multiply this with sideSteps to determine your Y coordinate. DON’T CHANGE THIS!

Y_PACE_LENGTH = 6

The maze is 35 steps along the X axis.

while steps <= 35:

Take the next step:

hero.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH)

Increment steps and sideSteps as appropriate, taking into account the special rules.

steps += 1
if steps <= 6:
sideSteps += 1
if steps > 6 and steps <= 11:
sideSteps -= 1
if steps == 12:
sideSteps += 5
if steps == 14:
sideSteps -= 4
if steps > 15 and steps <= 18:
sideSteps += 1
if steps > 18 and steps <= 21:
sideSteps -= 1
if steps > 22 and steps <= 23:
sideSteps += 3
if steps > 33 and steps <= 34:
sideSteps += 1


#4

Please take the time to learn how to post your code correctly. Help us help you. The way you posted it, we can’t see the structure.


#5
Ok here is the code:
sideSteps = 1
steps = 1


X_PACE_LENGTH = 4


Y_PACE_LENGTH = 6
SWITCH = 7
SLIDE = 8
SKIP = 11
sidemove = 1

while steps <= 35:
    hero.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH)
    if (steps % SWITCH == 0):
        sidemove = sidemove * -1
    sideSteps += sidemove
    if (steps % SKIP == 0):
        sideSteps = sideSteps + sidemove
    if (sideSteps > SLIDE):
        sideSteps = sideSteps - SLIDE
    if (sideSteps < 1):
        sideSteps = sideSteps + SLIDE
    steps += 1
    

sideSteps = 1
steps = 1


while steps <= 35:
    hero.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH)
    if (steps % SWITCH == 0):
        sidemove = sidemove * -1
    sideSteps += sidemove
    if (steps % SKIP == 0):
        sideSteps = sideSteps + sidemove
    if (sideSteps > SLIDE):
        sideSteps = sideSteps - SLIDE
    if (sideSteps < 1):
        sideSteps = sideSteps + SLIDE
    steps += 1

#6

oops copied the while steps twice. My bad.