# G4P ToggleButton (change state)

**URL:** https://discourse.processing.org/t/g4p-togglebutton-change-state/30063
**Category:** Libraries
**Created:** [May 12, 2021, 11:59am UTC](https://discourse.processing.org/t/g4p-togglebutton-change-state/30063 "2021-05-12T11:59:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Liu.Exit](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@Liu.Exit](https://discourse.processing.org/u/Liu.Exit)
#### Post date: [May 12, 2021, 11:59am UTC](https://discourse.processing.org/t/g4p-togglebutton-change-state/30063/1 "2021-05-12T11:59:31Z")

</div>

Hello,  
is it possible to change the state of “G4P ToggleButton” other than with the mouse?  
(For example by receiving information from the serial port.)  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cf40cfcad85d9d6f8f04602b01ec0ffda291abee.png)

Thank you

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [May 12, 2021, 12:53pm UTC](https://discourse.processing.org/t/g4p-togglebutton-change-state/30063/2 "2021-05-12T12:53:07Z")

</div>

You can change the state of a GimageToggleButton with the statement  
`button.setState(ns);`

where `ns` is the new state number. If the button has 2 states then use ns = 0 or 1

In general if the button has `nbrStates` then `ns` can be in the range `1` to `nbrStates - 1`

---

<div class="post-metadata">

### Author: ![Liu.Exit](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@Liu.Exit](https://discourse.processing.org/u/Liu.Exit)
#### Post date: [May 13, 2021, 7:29am UTC](https://discourse.processing.org/t/g4p-togglebutton-change-state/30063/3 "2021-05-13T07:29:59Z")

</div>

Thank you .  
it’s cool.  
As I am not familiar with the English language, can you tell me where I can find a document with the list of functions related to the different buttons?

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [May 13, 2021, 9:34am UTC](https://discourse.processing.org/t/g4p-togglebutton-change-state/30063/4 "2021-05-13T09:34:16Z")

</div>

First of all try my website - it has some [guides](http://www.lagers.org.uk/g4p/guides/g01-introduction.html) for the more advanced features of G4P and the online [API reference](http://www.lagers.org.uk/g4p/ref/index.html) (JavaDocs)
