Sets the number for the specified screen element.
Your apps will sometimes need to change, or clear, the numbers displayed on screen elements*. setNumber()
can be used to update the number on a textInput, textLabel, button or slider screen element.
*The slider design element was contributed by Mike and Mitchell Schmidt.
Update the number on a button with every click.
// Update the number on a button with every click button("clickCounter","0"); onEvent("clickCounter", "click", function() { var count=getNumber("clickCounter")+1; setNumber("clickCounter", count); });
textLabel("randomNumber",""); setNumber("randomNumber",randomNumber(0,100));
Demonstrate setting the number on a slider. Assumes sliders named xPositionSlider and yPositionSlider have been placed on the screen in design mode.
// Demonstrate setting the number on a slider. Assumes sliders named xPositionSlider and yPositionSlider have been placed on the screen in design mode. onEvent("screen1", "click", function(event) { setNumber("xPositionSlider",event.offsetX); setNumber("yPositionSlider",event.offsetY); });
setNumber(id, number)
Name | Type | Required? | Description |
---|---|---|---|
id | string | The unique identifier for the screen element. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _. | |
number | number | The number displayed within the screen element. |
No return value. Modifies screen only.
setText()
with sliders which require a number to be set.Found a bug in the documentation? Let us know at documentation@code.org