Reset all variables on a page (or at least button counts)

Hi. I’m wondering if there’s a way to have a button reset a page as if it were just arrived at. Alternately, can I set a button to reset the pressCount of a different button to zero? I can’t figure out if resetOnChange can do this. Thanks!

Well, if you’re just trying to use the pressCount for something. You could have a “reset” button capture the current pressCount. And have a variable for the effective pressCount as the difference between the actual pressCount and the pressCount when the reset was pressed.

capture("pCount"): buttonName.pressCount
effectivePressCount = numericValue("${buttonName.pressCount}-${resetButtonName.lastValue("pCount")}")
1 Like

Very clever! I’m not sure that works for me, though. I have four other buttons on the page, each of which I’m using as a three-way toggle (0, 1 or ?). They will all have been clicked a different number of times. I want a fifth button to reset them all to their initial states (which may also be different for each button.). Hmmm.

Same process should work. You can have multiple captures for the same button.

capture("p0"): b0.pressCount
ePC0 = numericValue("${b0.pressCount}-${reset.lastValue("p0")}")
capture("p1"): b1.pressCount
ePC1 = numericValue("${b1.pressCount}-${reset.lastValue("p1")}")
1 Like

Excellent. I think this clicked for me now. Thanks!

Can you please clarify how this works?
If this is the code for a separate “reset” button, how would buttons “b0” and “b1” know that they have to change their effective changeCount?
Thank you.

The effective counts are created in the reset button’s CL, but variables in any component can be referenced by other components if needed.

myVar= componentName.script.refVarName

So how will it look for button’s b0 CL pressCount?

Edit the Computation Layer Script for b0

hidden: this.pressCount > 0
pressCount = reset.script.effectivePressCount  #this doesn't seem to work

Edit the Computation Layer Script for reset

capture("pCount"): b0.pressCount
effectivePressCount = numericValue("${b0.pressCount}-${reset.lastValue("pCount")}")

Button b0 has many functions, and I need it to be reset after all procedures are completed so that the cycle could be repeated as many times as needed.

“this.pressCount” references the actual pressCount of the component, not the pressCount variable you made. Remove “this.” and I think it should work the way you intend.

Probably better practice to not name variables the same as sinks or sources. For example, i know a lot of people make “correct” variables and confuse themselves trying to reference the “correct” sink at times they haven’t defined the variable. I prefer “check”.

I tried this, and it didn’t work :((

Edit the Computation Layer Script for “test” button

hidden: pressCount > 0
pressCount = reset.script.effectivePressCount  

Edit the Computation Layer Script for “reset” button

hidden: test.pressCount = 0
capture("pCount"): test.pressCount
effectivePressCount = numericValue("${test.pressCount}-${reset.lastValue("pCount")}")

Is your desired behavior that

  1. The reset button is only hidden before the rest button is pressed, and continues to remain visible thereafter.
  2. The test button hides when pressed and reappaears when reset is pressed.

If so, easier might be for “reset” CL:

hidden: test.pressCount>0

… and for “test” CL:

hidden: this.pressCount>reset.pressCount

Well, it’s not what I need.
I need an action button that allows to perform several actions. After all is over, I need a reset button to reset the action button to its original state.

Big thank you for your time and effort to help.

Can you use clickable buttons on a graph instead of action buttons? They are much easier to use and do resets and such.

How do you do that? I would appreciate a more detailed instruction because I am a rookie.

Sure. But can you explain more what you want it to do? I can’t really tell from your previous post. Making a reset is not a problem but I’m not clear what it means for one button to do multiple actions.

Gladly. For example,

Action 1. Show graph with the initial bounds (-10,10,-10,10). Students will be able to set new bounds with a Zoom Box.
Action 2. Zoom In. Students explore the graph within the new bounds.

RESET. Show the graph with the initial bounds and ready to repeat Action 2.

Ok, here is an example: graph with zoom • Activity Builder by Desmos

There are actions in Desmos which are created using an arrow ->. You can use these to set the value of a variable. So you can make an action, and assign it a name, like a_ction1 = n → n + 1 , which would increase n by 1. You then make an object clickable (it can be a point, a polygon, a graph, whatever) and then type a_ction1 in the click field. When you click, it will then run that action.

In this case, since you want an alternating on/off thing, I used modulo 2. So basically just keep increasing the number of presses, but then create a conditional that sets it to 1 or 0 depending on the value mod 2.

Let me know if you have any questions or if you need a different example.

This is what I actually have in mind. Please have a look. I do not know how to return the page to its original condition.

Rounding Calculator

Ok, take a look now. I combined everything into 1 graph on the left, using conditionals. And on the right, I made a single button that cycles through the action number. graph with zoom • Activity Builder by Desmos

Also, you may be interested in this activity: Multiple Zooming Number Lines (clickable version) • Activity Builder by Desmos