How to create a quizz/trivia game only using umg/bp ?

Hello.

I would like to create a quizz/trivia game for a personnal project. But I have no idea where to start.
The project should be simple since I only need a main menu, questions and an end screen for the results.

Right now I’ve only managed to create the main menu … But I haven’t figured out how to do the questions.
I already created a widget with a question and 4 possibles answers. But using that method will require me to create a widget for each questions …

Here’s what I got so far.

For the last Widget. My goal would be to dynamically display the number of question. For instance if I setup 30 questions it should display on the first question “Question n° 01 / 30” etc …
Where it says “Question goes here” this text should be replace everytime by a question store in a variable, a text file or anything that works. Same for the answers.

And if the player check the right box and press next, nothing should be displayed on screen but his score need to be store to be displayed at the end of the game.

Sounds pretty straightforward and you described it well.

  • you only need 1 widget for this and update its fields
  • flag the question and answers text blocks as variables (tickbox at the top of the details panel)
  • create a Struct that has a question and answers - 5 text variables (and maybe an int to indicate which questions is correct)
  • create a Data Table based on that struct (or use an array if you do not care about external files)
  • populate the whole thing as you see fit (manually or load from csv file)
  • have the next button increase an Index int (clamped to the number of questions you need)
  • have the Index int fetch a row from the Data Table or array
  • break the resulting struct and feed the content to the widget’s text blocks (set their text)
  • you can use that Index to show which question you’re at (out of however many you want to use)
  • don’t forget to reset the checkboxes when the next question is loaded

Do tell if any of the above makes little sense.

Thank you for this answer. I’ll try this when I’ll have some time.
Well right now juste by reading I’ll say that I’ll run into some issues since I’m not a pro (Data Table part)

But first I’ll try to figure it out myself just using this answer. And if I have question or issues I’ll ask :wink:
Thanks again.

also i would check out the thread linked below as the person there is attempting to create a similar system. like Everynone said though i would create a datatable to hold all your questions and answers then you just need a function that compares the selected answer to the correct one.

Makes sense to take it one bit at a time; to give you some headstart, a struct would look like this:

Called QA_Struct, here.

You can make the DT like so:

Double click it in the content browser and edit it:

To make things easy, make row names numerals.

Well. I tried looking at your link Thompson. But all I manage to do is this:

I have no idea how to link my text to the text reference from the widget.
And Everynone I’ve only been able to create the Struct and the DataTable.
This part’s in chinese for me:

No worries, it seems to me you’re doing well.

In the widget, create an int variable, let’s call it QuestionIndex; Next button’s onClick will increase its value by 1 every time it’s clicked:

Use this variable to fetch the row from the DataTable, and set questions’ and answers’ text values.

Thank you. For now it’s working like it should. But I have one question. I don’t really understand how the Integer from the Struct work.

I guess it’s to determine wich answer is correct. If so how does it work ? 1 = Answer 1 2= Answer 2 etc … ? And if that’s correct how can I use it to determine if the player check the right answer or not.

Thanks.

Yup, you’re right about the correct answer int.

When the player clicks next, iterate through the checkboxes and check if one of them is ticked, compare its index to the correct answer int.

It would look similar to this:

Completely untested but should work.

Ok great. I’ll check that out. Right now I’m very confused about something …
My questions are not aligned. The basic text that get replaced in my widget is centered and anchored to the center of the screen.

When the questions is short. The text is centered. But when it goes to a longer question (around 30 characters) my text is aligned to the right.

And this is the widget:

Is the text justification set to centre? Also, you can set alignment to .5 | .5 and size to content.

Alignement .5/.5 =

And if I leave it by default and I check size to content and justification center:

Think I just found a “solution”

Using a scale box seems to do the trick :slight_smile:

Unnecessary but sure, if it works for you.

Setting the anchors correctly would work better, cleaner, neater and with less elements, and would work with all screen sizes. You’d need to remove the manual offsets you punched it. Or choose the central icon from the anchors menu and ctrl+click and then shift+click it to reset it all.

It seems to do the trick because it becomes a new canvas child with default settings rather than custom offsets.

Can’t get it to work with me…
I think I did it right. But now I don’t know how to link the old part that set the text (up)
With the new part (bottom).
I tried adding a print string but when I check a box and press next nothing happen.

You need both of them going off, sequence node is your friend here. Also make sure that the Correct Answer in the DT is set to something else than 0. Also make sure that row names are numerals.

To be honest, I’d store the correct answer in an int (when you set widget text) rather than access the DT twice.

The row names are 1 to 5 and the answers are not 0.
I added a sequence node but now even if I pick the right answer I have a failed answer …

I have no idea how to store a variable after I set the widget text. All I need is to store that variable. If the player choose the right answer +1 to the Score variable if not +0.
I know how to add a variable and change it’s value. But right now I have no clue on how I’m supposed to link that variable to my Set Text (text) when the question is generated from the DT.

The row names are 1 to 5 and the
answers are not 0.

They’re in the 1-4 range, right?

Here’s what I meant, seems to be working fine:

I have no idea how to store a variable
after I set the widget text.

Called CorrectAnswerForThisQuestion above.

If the player choose the right answer
+1 to the Score variable if not +0. I know how to add a variable and change
it’s value. But right now I have no
clue on how I’m supposed to link that
variable to my Set Text (text) when
the question is generated from the DT.

You could try something like this:

Run this only if the answer is correct.


Do note that I’m not giving you the whole correctly working setup here, these are just elements allowing you to do it. You need to logically organise it.

So check if the correct answer is selected first, count the score, and then load the next question. Sorry, no time for more details. Not at the moment. I can have a closer look at it on Monday morning maybe. In case you can’t get it to work right.

It might just work fine if you run it in the other sequence order than in my screenshot. onClick should check the answer and then load the next question. You probably will want to setup some logic that loads the first question, too.

Well still not working for me … When I pick the correct answer it tells me I’m wrong …
I have 5 rows in my DT named: 1, 2, 3, 4 and 5

For example at the row number “3” the correct answer is the answer number 4 (A4). So in the “CorrectAnswer” integer I typed “4”
But in game if I pick the answer number 4 → My string pops up

.
(Update: I just tried every answer on this question and I only got a “success” on the third answer not the fourth …
I don’t get it … Is my “CorrectAnswer” int wrong then ?

Thanks.

Hey,

I wrote this on my lunch break:

It’s far from perfect but works well for what it is. Based on what we discussed above and comes with a couple of extra features. Feel free to take it apart and see what makes it tick. The entire logic is in the widget.

GoogleDrive link to the project:

https://drive.google.com/open?id=1qj8vzSw8IFqmdWO7pbaP4aERynj1RcGC

Let me know if something makes little sense.

1 Like