[Solved] Two State button

I need help. I cannot seem to make a button that is toggleable. I am trying to make a settings menu and I cannot because the button never works. I’m trying to make a button in the settings menu that when it is off and you click it then it turns on and vice-versa for particles. A button to turn off particles. But each time I click it the button still says on and the particles stop for a mili-second then turn back on.

http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/how-to-make-togglable-states-with-variables

1 Like

Arthur: i think an error occurs in this part of the Wiki.
We must read this as corrected by me, is’nt it:

image

No, not at all. What you want is one state to change every time the trigger condition is met. The whole purpose of this variable is making sure once the state has been changed oncey it doesn’t get modified by the next ones. Changing the last action changes nothing (as said in the wiki it is redundant but left in for consistency) and changing the condition would make it so it would only trigger if the state just has been changed by the other state changing event. That is the total opposite of the goal of the events

Subtil!
I made a mistake of understanding of the problem: it was not a toggle button we wanted but in fact a button with once state only.

Thanks Arthur for the precision.

You error I think is more that you have mistaken the state with the variable used to make state togglable

Ah, ok. I understand now.
Thanks!

Thank You!

I haven’t tested your response yet but I think it’ll work for what I’m trying to do, thank you.

#Python.
import os, time

def term_clear():
    if os.name == "nt":
        os.system("cls")
    else:
        os.system("clear")

user = "arthuro555"
print("Thank you " + user)
time.sleep(2.5)
term_clear()
# (Just wanted to show that I did know how to code lol.)

The str() is redundant as user is already a string

Yeah. It would be more for input not the variable but thanks. I did test your answer and…

public class Main {
    public static void main(String[] args) {
        System.out.println("It works like a charm.");
    }
}
//It works like a charm.
1 Like