Sarven Saivor code broken Javascript

Hello.

I Was just wanting to pick this level, And when I did, And, The sample comments and all are broken.
I just don’t like this, Since, I’m pretty sure this Sarven Savior Level is only for python coders.

The comments are all Hashtags # And, For some reason, the code is broken. I am coding in Javascript, And would like to know if you can fix this.
Javascript Comments are //
Here’s the code:

// An ARRAY is a list of items.

// This array is a list of your friends' names.
var friendNames = ["Joan", "Ronan", "Nikita", "Augustus"];

// Array indices start at 0, not 1!
var friendIndex = 0;

// Loop over each name in the array.
// The .length property gets the length of the array.
while (friendIndex < friendNames.length) {
    // Use square brackets to get a name from the array.
    var friendName = friendNames[friendIndex];
    
    // Tell your friend to go home.
    // Use + to connect two strings./*
  Steps for using:
    1. Go to the level editor for the level.
    2. Double click the Hero Placeholder to edit it.
    3. Run the level so you have the child window open.
    4. Make sure the equipment you have equipped matches the hero's equipment for for the course.
    5. Copy paste the solution code from the level editor into level, press run/submit. (Just want all the frames to load and ensure it succeeds)
    6. Put this script into the console of the level-editor tab/window
  Now everything (seed, equipment, frames, hash) should be added to the solutions.
*/

(function () {
  var currentView = globalVar.currentView;
  if(!currentView.subviews.thangs_tab_view.editThangView) throw "No thang selected, double click the hero placeholder."
  var thangData = currentView.subviews.thangs_tab_view.editThangView.thangData
  var oldPath = currentView.subviews.thangs_tab_view.editThangView.oldPath
  var pComp = _.findWhere(thangData.components, function (elem) {return elem.config && elem.config.programmableMethods}).config.programmableMethods.plan
  var solutionArray = pComp.solutions;
  var solutions = {
    "python":{},
    "javascript":{}
    //"lua":{},
    //"coffeescript":{}
  };
  for(var i = 0; i < solutionArray.length; i++) {
    solutions[solutionArray[i].language].solution = solutionArray[i];
    solutions[solutionArray[i].language].index = i;
  }
  for(var key in solutions) {
    var solution = solutions[key].solution;
    console.log(solution);
    if(!solution) {
      solution = {};
    }
    var index = solutions[key].index;
    
    if(!solution.source) {
      if(key == "javascript") {
        solution.source = "TODO WRITE SOLUTION: \n" + pComp.source;
      } else {
        solution.source = "TODO WRITE SOLUTION: \n" + pComp.languages[key];
      }
    }
(unexpected Index, Solution.language)
 solution.language = key;

solution.succeeds = true;
    if(solution.passes) {
      delete solution.passes
    }
    var childWindow = currentView.childWindow.globalVar;
    if(!childWindow) throw "No child window, press run.";

    var dif = childWindow.currentView.session.get('state').difficulty;
    if(dif) {
      solution.difficulty = childWindow.currentView.session.get('state').difficulty;
    }
    solution.seed = childWindow.currentView.world.randomSeed;
    var tInv = _.findWhere(currentView.subviews.thangs_tab_view.editThangView.thangData.components, function(elem) {return elem.config && elem.config.inventory})
    if(tInv) {
      tInv = tInv.config.inventory;
      solution.heroConfig = {
        inventory: tInv,
        thangType: currentView.subviews.thangs_tab_view.editThangView.thangData.thangType
      }
    } else {
      console.warn("No recommended inventory found, using the child window's equipped gear.")
      solution.heroConfig = childWindow.currentView.session.get('heroConfig');
    }

    var hist = childWindow.currentView.session.get('state').flagHistory;
    if(hist && hist.length > 0) {
      solution.flagHistory = hist;
    }

    if(childWindow.currentView.world.frames.length >= 2) {
      solution.lastHash = childWindow.currentView.world.frames[childWindow.currentView.world.frames.length - 2].hash;
    }
    solution.frameCount = childWindow.currentView.world.frames.length;

    var goals = {};
    for(var i = 0; i < childWindow.currentView.goalManager.goals.length; i++) {
      goal = childWindow.currentView.goalManager.goals[i];
      goals[goal.id] = childWindow.currentView.goalManager.getGoalState(goal.id);
    }
    solution.goals = goals;

    if(index !== undefined && index !== null) {
      pComp.solutions[index] = solution;
    } else {
      pComp.solutions.push(solution);
    }
  }
  Backbone.Mediator.publish('editor:level-thang-edited', {thangData: $.extend(true, {}, thangData), oldPath: oldPath})
  currentView.subviews.thangs_tab_view.editThangView.render()
})();
    hero.say(friendName + ", go home!");
    
    // Increment friendIndex to get the next name.
    
}

// Retreat to the oasis and build a "fence" on the X.

CodeCombat - Coding games to learn Python and JavaScript?

NVM, Where;s the editor Button?

Just paste the code instead of what you have and then solve:

// An ARRAY is a list of items.

// This array is a list of your friends' names.
var friendNames = ["Joan", "Ronan", "Nikita", "Augustus"];

// Array indices start at 0, not 1!
var friendIndex = 0;

// Loop over each name in the array.
// The .length property gets the length of the array.
while (friendIndex < friendNames.length) {
    // Use square brackets to get a name from the array.
    var friendName = friendNames[friendIndex];
    
    // Tell your friend to go home.
    // Use + to connect two strings./*
    hero.say(friendName + ", go home!");
    
    // Increment friendIndex to get the next name.
    
}

// Retreat to the oasis and build a "fence" on the X.`
2 Likes

Thanks! Helped a lot!

You’re welcome
Just click the post with the solution as a solution

1 Like

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