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

Need advice for lost viking code


can any one please advise what is wrong with this code
i use xStep instead of steps and ystep instead of slidStep and i use S to change from north to south

The Code IS :

    # 1- always increament X +=1
    # 2- increament Y +=S
    # 3- initial S=1
    # 4- if to switch > change S to -S 
    # 5- if to Skip > increment Y +=S in addtion to the normal increament
    # 6- if the Y more than slide (9)  > set it to  (1)
    # 7- if the Y less than (1)  > set it to (9) 
    # 8- increment Ttoal Steps 
    # Vars & Intials
    SLIDE = 10
    SWITCH = 7
    SKIP = 11 
    xSTEP = 1
    ySTEP = 1
    S = 1
    while xSTEP <= 35:
        self.moveXY(xSTEP * X_PACE_LENGTH, ySTEP * Y_PACE_LENGTH)
        if xSTEP%SWITCH == 0:
            S = -S
        if xSTEP%SKIP == 0 :
            ySTEP += S
        #6 & 7 
        ySTEP += S 
         if ySTEP < 1:
             ySTEP = SLIDE
         if ySTEP > SLIDE :
             ySTEP = 1 
        xSTEP += 1

Please use the triple bacticks (```) to wrap all your code (I think you are using blockquotes, don’t use them).

From what I can tell:

  • Increment xSTEP last, since the next ySTEP depends on the current xSTEP.

  • The below is not right

if xStep % SWITCH = 0 : # that's assignment, not equality
  • You should be using SLIDE below (though it doesn’t matter much, until you get a new seed):
if ySTEP < 1:
    ySTEP = 9 # should be SLIDE

Finally one of the seeds I encountered required me when moving from sideStep = 1 to SLIDE move from 1 to SLIDE - 1. (Though I never encountered that one again, so…)


Thanks I adjusted the code and I passed the level , so should I leave the code now of there is a policy to remove it


You can leave it. While we agreed to not post full solutions on request yours is not a full solution. Others have to understand trotod’s explanation and your code to derive a working solution so the desired learning effect is still applied.


I think I cheated…
All I did was step on 1 mine to active all of them and run away. Everyone died (but me) and I walked to the skeleton.
So now I’m wearing a nice viking helmet.

1 Like

I got through this level with moveXY() in various places (will not post… obviously). Should there be a new set of boots that accept the slide commands w/o allowing moveXY()?


No new boots… It is hard to come up with a level that requires coding skills (this level is optional after all) and is not broken by some (labor-intensive) trick. You should need quite a lot of moveXY-commands there, and measure them exactly. Maybe it would help to disable the overlay that shows the coordinates under the cursor… I’ll propose that to Cat.


It only took 15 commands, because the firetraps were too spaced apart and my character could walk right between most of them.


Finally one of the seeds I encountered required me when moving from sideStep = 1 to SLIDE move from 1 to SLIDE - 1. (Though I never encountered that one again, so…)

I just encountered this, is there a way to tell what seed I’m using to help report it? Cause I changed my code 3x thinking I had it wrong before realizing this was intended…


Getting the level seed is apparently not that easy, but I will leave it here for future reference.

You can instead simply tell us the three variables you received, we can regenerate the level from that.

Getting the seed

Quote from HipChat:

Nick Winter
you can generate the seed from the session ID and the submit count, which you can get with… currentView.session.get('state')
and then look in the Existence System to see how the seed is generated

Enter the mentioned code-fragment in the JS-console, execute and … well, look in the existence system in the level-editor.


That’s a lot easier :smile:

slideStep = 8
switchStep = 6
skipStep = 11


Wow! Thanks, my code failed miserably, but with the help from the first reply and the initial post I did it!


Or… you know… you could hit the “like” button…


Cam you please write down the full code that is fixed?


We do not give out correct code on these forums. CodeCombat’s purpose is to help people “learn how to code by playing a game.” You can not learn how to code if you don’t do coding.

1 Like

No, you should be able to use the false code and @trotod 's edits to win. That is part of the learning process :smile:


I have this seed right now. How do I fix it???


Scroll upward a little more and you’ll find your answer.


Having difficulties with the same level:

SKIP = 11

north = True
sideSteps = 1
steps = 1
i = 1
while steps <= 35:

    self.say("step: " + steps + " side step: " + sideSteps)
    self.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH)
    if steps%SWITCH == 0:
        north = not north
    if steps%SKIP == 0:
        i = 2
        i = 1
    if north == True:
        sideSteps += i
        sideSteps -= i
    if sideSteps < 1:
        sideSteps = SLIDE
        north = False
    if sideSteps > SLIDE:
        sideSteps = 1
        north = True
    steps += 1  

After step 12 sidestep 8 the hero goes to 13/1 and blows everything up.


Your code learned me something new, even though i already solved the puzzle in another way, you taught me about the North = not North function, that might be handy sometimes.

Anyway, your code works just fine, but you should delete two lines that do nothing except break otherwise good code.
The north booleans in the slide section of your code should not be there.