Hi there! I’m new here. First of all - thanks for GDevelop. It’s great software. Try to learn very basics and stuck. Sorry if question real stupid.
I’m try to make switch button but dont get logic. Try this:
But its never work. What am I doing wrong?
Your “switchOn” variable goes right back to 0 just after it has been set to 1.
So… both condition triggered at once? I hopes “Trigger once” help with it but maybe it dont. How do can I fix it? Sorry for bother but right now I don’t get it.
You can use an extra variable, that emulates the “else” in programming:
first of all you don’t use sub events for no reason, I don’t see any reason for most of your logic to have sub events . Better do this.
Condition: variable SwitchOn is > 1 ==> Action: do = 0 to variable SwitchOn
Condition: variable SwitchOn is < 0 ==> Action: do = 1 to variable SwitchOn (this second event is not necessary, but in case)
now this is the main event you want
Contidition: the cursor/touch is on new object ==> Action: do +1 to variable SwitchOn
Touch or left mouse button is down
yes that’s right add 1 to the variable switchon every time it clicks on the new object
Note: no need to tell the computer that the variable switchon is 1 or 0
I think that Lizard-13 solution is better.
Solution by Lizard-13 works great, but Umar’s solution very interesting too. Thanks a lot! Now I understand how to make this switch button and learn something about GDevelop logic.