How to use doReset()

The Basics

If you don't have doReset() in your layer then add it.
doReset(layer){
  // put code here
},

Generally you don’t want a layer to reset another layer on the same row. You definitely don’t want your layer to be reset every tick by a side layer.

You should also make it possible to reset the layer.

doReset(layer){
  if(layers[layer].row <= layers[this.layer].row || layers[layer].row == "side")return;

  layerDataReset(this.layer)
  /*
    that giant if does 2 things
    first it gets the resetting layer's row and makes sure
    it's higher than the current layer's row

    second it gets the resetting layer's row again
    and checks if it's a side layer
    if either of those are true then it returns
    nothing which ends the function

    the other line resets the layer
  */
},

Keeping Stuff on Reset

If you want to keep anything on reset you need to change layerDataReset().
doReset(){
  ...
  layerDataReset(this.layer, ["upgrades"])
  /*
    this would let you keep upgrades on reset
  */
},

Of course, you wouldn’t normally want to always keep upgrades on reset. If you want to lock keeping upgrades behind a milestone you do this:

doReset(){
  ...
  let keep = []
  // declare keep
  
  if(hasMilestone(<layer>,<id>))keep.push("upgrades")
  // check for the milestone and push "upgrades"
  // keep is now ["upgrades"] if you got the milestone

  layerDataReset(this.layer, keep)
  // reset with keep
},

You can also do it with “milestones”, “points”, “buyables”, “challenges”, and any other variable in the player.<layer> object.

The previous code keeps all upgrades on reset. If you don’t want that, you can do this:

doReset(){
  ...
  let keep = []
  // declare keep

  if(hasMilestone(<layer>, <id>))keep.push(11, 12, 13)
  // push the upgrades we want to keep
  // keep is now [11,12,13] if you have the milestone

  layerDataReset(this.layer)
  // reset
  
  player[this.layer].upgrades = keep
  // upgrades = keep
},

You can also combine these!

doReset(){
  ...
  let keep = []
  let keepupgs = []
  // declare keep and keepupgs
  
  if(hasMilestone(<layer>,<id>))keep.push("milestones")
  // check for the milestone and push "milestones"
  // keep is now ["milestones"] if you got the milestone

  if(hasMilestone(<layer>, <id>))keepupgs.push(11, 12, 13)
  // push the upgrades we want to keep
  // keepupgs is now [11,12,13] if you have the milestone

  layerDataReset(this.layer, keep)
  // reset with keep

  player[this.layer].upgrades = keepupgs
  // upgrades = keepupgs
},

Of course there’s more you can do but you should only need this most of the time.

5 Likes

There’s a small bit of information from the docs about it as well (although I think gapple’s explanation is more thorough and easy to understand):

  • doReset(resettingLayer): optional . Is triggered when a layer on a row greater than or equal to this one does a reset. The default behavior is to reset everything on the row, but only if it was triggered by a layer in a higher row. doReset is always called for side layers, but for these the default behavior is to reset nothing.If you want to keep things, determine what to keep based on resettingLayer , milestones , and such, then call layerDataReset(layer, keep) , where layer is this layer, and keep is an array of the names of things to keep. It can include things like “points”, “best”, “total” (for this layer’s prestige currency), “upgrades”, any unique variables like “generatorPower”, etc. If you want to only keep specific upgrades or something like that, save them in a separate variable, then call layerDataReset , and then set player[this.layer].upgrades to the saved upgrades.
1 Like