0 votes

I am creating a quiz game. The answers are button which are in random colours . When a answer is choosen the selected button should change it's colour to white. If the answer is correct the white colour remains but if the answer is wrong the button should return to it's first colour before selecting . Can anyone tell me how to do it ?

asked Nov 29, 2019 in Projects by THE HELIX (140 points)

1 Answer

0 votes

You could put the normal color of the button in a variable, this way you will be able to restore it if needed.

Example code (adapt to your needs):

extends Button

var _normal_color : Color

# Call this after you assigned the color to your button,
# assuming you used `modulate`
func remember_color():
    _normal_color = modulate

# Call this when you need the button to become white
func make_white():
    modulate = Color(1, 1, 1)

# Call this when the answer is wrong
func restore_color():
    modulate = _normal_color
answered Nov 29, 2019 by Zylann (26,782 points)

I didn't understand.can u please show me how to save it ?

I don't know how else I could show that to you... the code I provided is litterally explaining what you need to do. I don't know how you made the rest of your game so doing it in your project would obviously be a little different, but I thought you could figure out from my example how to do it in your case.
At this point you could share your project and I can modify it to show you how it can be done specifically in your project... unless you have no project at all and you are asking how to do the WHOLE thing?

I put your code in the game.Now on pressing the buttons they change to white but if it is a wrong answer they are not changing to original color they remain in white color only.
In the game I have put all the correct answers in an autoload script and access them using the script attached to buttons.

I still don't understand how exactly your project is made, there are details I don't get. For example, you say when a button is pressed it changes to white, but when it's a wrong answer it doesn't change back to its color... but when are they supposed to go change back? Why would they become white? Is there a timer? Is it only white when the button is being held?

It also seems you haven't much knowledge of scripting in Godot. Did you follow the tutorials? http://docs.godotengine.org/en/3.1/getting_started/step_by_step/index.html

Sorry my project is not a quiz game but a game similar to the imageenter image description here

In the project there are circles of different colors, randomly arranged.I need to match same colored circles. When I press same colored circles they change to white and are cleared. But when I select different colors they change to white ; since they are different colors I need to change their color from white to their original color [Here white color is used for selecting].
How to change the circles white color to their original color if the selected circles are of different color ?

Here is the project Game

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.