Add counter to button press

Hi,

I am completely new to UE4 and making games. I am making a quiz game where the user runs into a collision box and a multi choice question appears. I want to add a counter to count how many times they press the A key for example, to count how many questions they got correct and display it at the end.

Here are my blueprints for one hit box.

Any help you can give to a newbie would be very much appreciated!
276322-

1 Like

Hi, here’s how I you can do it. Make an integer variable for counter, I called it “Counter”. Put Get and Set of that variable and connect them like on the picture below.

Basically what you get now now is every time you press the A button, your value from Counter variable will be increased by 1 and it will Set that as the new value for Counter variable in the Set node.

276328-counter1.png

You could also do it like this

276329-counter2.png

It’s pretty much the same, except that now instead of increasing the Counter value through “Integer + Integer” node where you can specify the value by which you want to increase the Counter, we are now increasing it by 1 and you can’t change that. It’s “Increment” node, and it will increase value by 1.

I hope I explained it well and you can follow.

1 Like

Thank you so much.
Do you know how i would get this to display once all the questions have been answered?

Yes I know. It will take a little bit more work so I’ll upload a video or a file here in a few minutes.

Did you learn anything about Widgets? (that’s the user interface like buttons and stuff)

Yeah, I have a few widgets and thats how i get the questions to pop up. Its just the blueprint part i am struggling with.

For getting the counter value to display you will need to create a widget and have a text box or something that you modify to equal the value of the “count”. I have a bunch of beginner friendly blueprint tutorials that I think will help you get a good foundation of how this can work. Check out video #10 I created a “score” box for the player but you can just as easily have this be the number of button clicks :slight_smile:

I see. Here’s how you show the result as text in the end

https://we.tl/t-LJj8SVfa6a

I wrote everything in Word doc but I can’t upload it here, so it’s on the link

I tried to explain why we do some things but I didn’t go into much details because you said you know Widgets so I assume you covered it all by now.

Also I’d recommend you to watch this youtube channel it has great tutorials for beginners and I think that you’d have almost everything you need for your game once you’re done with his beginner tutorials.

Here’s the channel:

Haha thanks for spreading the word and support! I just posted a link like 30 min ago to my beginner series up above I guess I should have waited ha

Hahaha, you’re welcome, you deserve it. I started learning UE month ago and I was lost until I found your tutorials. Haha, I guess you can leave it to the community to spread it :stuck_out_tongue:

That’s awesome to hear! Glad they are filling a void in the tutorial realm :slight_smile:

Thank you so much, it works! :slight_smile:

You’re welcome :slight_smile: . I’m glad I could help :slight_smile: