🏠 back to Observable

I don't want this block to run continuously

I only want this block to run whenever the button which says Add 10 points is hit - currently it runs all the time for some reason!

the block is under the need help heading!

thanks :slight_smile:

Welcome to the forums @jajoosam!

Here’s a quick fix:

  • The reason you get an infinite loop is that the “need help” cell has a reference to total. For mutable variables, recall that mutable total is a non-reactive reference and total is a reactive one (meaning that when mutable total is changed, all cells that reference total will be re-run). The fix was just to replace total with mutable total
  • I got your viewof toAdd button to work by adding a reference to toAdd in the “need help” cell. The way views work, clicking on the button causes the button to dispatch an input event, which causes the runtime to re-evaluate all cells that depend on toAdd.
1 Like