# Sarven savior bug JS

**URL:** <https://discourse.codecombat.com/t/sarven-savior-bug-js/31926>\
**Category:** Bugs\
**Created:** [January 27, 2022, 2:44am UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926 "2022-01-27T02:44:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 27, 2022, 2:44am UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/1 "2022-01-27T02:44:35Z")

</div>

all the code look like this

```python
// 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];
      }
    }
    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.
    friendIndex += 1;
}

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

```

bug?? [@staff](https://discourse.codecombat.com/groups/staff)

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [January 27, 2022, 10:11pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/2 "2022-01-27T22:11:50Z")

</div>

Whats the bug exatly? @Haris

---

<div class="post-metadata">

**Author:** ![Vanessa](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vanessa/32/33899_2.png) [@Vanessa](https://discourse.codecombat.com/u/Vanessa)\
**Post date:** [January 28, 2022, 3:09am UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/3 "2022-01-28T03:09:24Z")

</div>

> [@Haris](#):
>
> `// Retreat to the oasis and build a "fence" on the X.`

You didn’t do this part, or at least I cant see it

also, is there an error? like wawa said, what is the bug?

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 28, 2022, 1:52pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/5 "2022-01-28T13:52:16Z")

</div>

as u can see the code not supposed to look like this

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 28, 2022, 1:57pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/6 "2022-01-28T13:57:13Z")

</div>

even i reload the code it still look like this

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 28, 2022, 2:03pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/7 "2022-01-28T14:03:47Z")

</div>

it show error “there a problem in your code”

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 30, 2022, 3:49pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/8 "2022-01-30T15:49:02Z")

</div>

Help! i can’t pass next level because of this.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 30, 2022, 4:00pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/9 "2022-01-30T16:00:35Z")

</div>

I just checked the level out, and i saw the same thing. I cleared out the junk and there is the starter code. Copy paste it instead of what you have then fill in the stuff required under the comments.  
@Haris

```python
// 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.

```

PS: that is the part that is weird, you can delete it

```python
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];
      }
    }
    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()
})();
    

```

@Chaboi_3000 can you see the source of the problem, so that other players won’t face the same thing

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 30, 2022, 6:11pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/10 "2022-01-30T18:11:26Z")

</div>

thanks @Aya 20 character

---

<div class="post-metadata">

**Author:** ![cheddarcheese](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cheddarcheese/32/22417_2.png) [@cheddarcheese](https://discourse.codecombat.com/u/cheddarcheese)\
**Post date:** [January 30, 2022, 7:22pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/11 "2022-01-30T19:22:47Z")

</div>

the same thing happened to me i just deleted all of the random stuff and got the code in working order

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 31, 2022, 5:01am UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/12 "2022-01-31T05:01:43Z")

</div>

You’re welcome (20chars)

---

<div class="post-metadata">

**Author:** ![Vanessa](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vanessa/32/33899_2.png) [@Vanessa](https://discourse.codecombat.com/u/Vanessa)\
**Post date:** [April 20, 2022, 6:34pm UTC](https://discourse.codecombat.com/t/sarven-savior-bug-js/31926/21 "2022-04-20T18:34:33Z")

</div>

you spelled author incorrectly if you were making it seem like you deleted it.

also, all of this is considered spam, so stay on topic.

(The posts i was replying to are gone so ignore this-)
