Hello world, please help me and excuse me for my english. I’m developing a 3d platform with 2d games to learn english.
As you can see in the pic there is a simple quiz game with 12 (of 40) random quiz with a black and white clipart on the left and 3 possible answers on the right. I think i have to do an array but i don’t know how. Questions and answers are all images.
Thanks for any help!!
you never asked a question. are you asking how you would store the information? explain your issue and be specific / add details.
Thanks ThompsonN13 and sorry beacuse i’m not clear. So the questions are:
Why my blueprint are not working? Yesterday i followed a tutorial and i did this.
I don’t now how to get the images in the widget. Questions are images (D1), Answers are images on buttons (R1, R2, R3)
And when i start the game, i can see the empty widget.
Other question is: how can i randomize the questions in the game?
Ok, for now, i have only 5 questions (Dom1, Dom2, Dom3, Dom4, Dom5) but i have to add other 35 questions later and the user/gamer will find every time 12 different question. Of course some questions will be repeated but no problem.
now the second picture covers the function check answer. here we simply get the current row from the datatable by using the variable we set earlier. then we compare the question image to the answer selected by the player. we use the answer number here and a select node to determine which image is being compared, then use the equal (==) operand to see if they are the same. if they are the same the branch will be true, if not then the branch is false. i left this part up to you aas to what happens when the answers are done but i imagine you would want to add some score as you show in your picture then call the get new question event to create a new question for the player to answer, you may want to congratulate them too. i just used a print string for testing.
now the last thing we need to do is to bind the brush variables to the images they correspond to. to do this we just select the image in the designer heirarchy section. then go to the details panel and in the appearances section look for brush, next to brush you will see a drop down that says bind on the right click that then select the appropriate variable. this will make it so the image always reflects the image set in the variable. also note how the alignment is set, i mentioned this earlier but this setting will allow the image to cover the entire button.
and thats about it hope that helps.
below i also posted how my structs and datatable were setup. the first picture shows the answers struct which stores the information about each answer, in your example it would show everything associated with orange for example. the next picture shows the questions struct and the questions datatable. on the left is the struct which is made up of 5 of the answer structs, so four answers and the question to be compared to. the datatable is of the type of the question struct and hold all the questions.
ThompsonN13, thanks for your great job. Simply fantastic.
Only one thing: Where can i store all the correct answers? Maybe i have to do another “DataTable” with the answer values struct?
“Answer Number” is an “int” variable?
what do you mean store the correct answers? are you looking to store the questions that have been answered correctly or store which answer is correct.
this also reminds me that i kinda messed up here, i made it so it checks for matching images when it should have been checking another value in the struct like a text or a bool. you could implement a bool that marks the right answer and it would actually simplify things, just add a bool variable into the answer struct.
anyways though if you wanted to make a list of the questions the player gets right then you would just add the current dt row to a array for each one they got right.
“Answer Number” is an “int” variable?
that isnt a question or a complete thought so not sure what im meant to do with it.
Thanks again for all your help. It works “almost” everything. Almost because when i play, the quiz stops at first question. It can compare correctly the question and the right answer but… only the first question works. So i put the “forloop” but nothing changes. I can play only with the first question. Do you have some idea?
you dont need the loop. what you need to be doing is calling the get new question event once the previous question has been completed.
basically first question comes up, player answers said question, you check the answer, you congratulate the player, then you call the newquestion event to load a new question.
the random int node is there so it loads a random question from the list each time. it has nothing to do with when a new question shows, just which question will show.
I don’t know how to call the newquestion event to load a new question.
Loopfor seems to be perfect because it does something (in loopbody) and when loop is completed, it loads a widget with congratulations and close the game.
Anyway Loopfor not works, DoN times not works.
Most important thing, i have to work after 2 red nodes (event construct and getNewQuestion) or after last set blue node on the right?
Please, be patient, I’m not an expert unreal engine user.
using loops is a basic skill, if you knew how they worked you would understand this is not the place for basic for loops, since your new just trust me on this. what you want to do is create your own looping behavior.
to do this you need to call the custom event, to call a custom event you just need to search for the node, right click a empty area in the graph then type in get new question, you should see one that says call getnewquestion. i dont have unreal open atm but is you selected the right one you will have a blue node that says get new question, when this node is activated it activates/runs/calls the getnewquestion event.
now you just need to place the call node in the appropriate place in the script, such as after where you congratulate the player or after checking the answer, basically place it where the timing will be correct for your circumstance. if you want to just add for testing to see how it works then add another button and have its on click script connected to the call getnewquestion node.
you really should go back to basics and learn the simple things by watching some of the beginner playlists on the unreal youtube channel. also your explanations are lacking clarity and details making them hard to understand. i realize you from italy and theres a language barrier but thats all the more reason to have a thorough explanation.
You’re right, i have to go basics to learn simplest thing. Anyway thanks again for all your answers.
I followed your suggestion and i created a new blue node (get new question) as you can see in the picture.
It works: when i answer a question (with right answer i listen to the correct sound and increase the score in the widget hud; with wrong answer i can listen another sound), i get another question. So i can answer to the other question and so on… forever. Yes, it repeats to infinite,
I have another problems: i would like to answer to only 12 questions, non infinite.
If you want to only be asked a set number of questions then you need to add script for that. All you really need for this a int variable that gets decremented each time a question is asked. Then have a check to see if the in is less than 1 then branch, if the in is less than one you dont have questions left and you would return to the main menu or whatever tou want, if the in is greater than 0 then you proceed with loading the question. You could put this script just after the get new question event
Ok, i did the branch with the condition. It compiles without any errors. But i continue to play at infinite questions and it never stops.
I created an int variable “Max” and i assigned a value par example 4. So i put the condition in the branch “Equal to 0”.
So, when the condition is false, there is another “new question” and for each iteration it should decrease of 1, right?
When the condition is true, it shows “Game completed” and exit.
Why not works and the game continues forever?
a few issues here, first and most important you currently have 1-max or 1-4= -3, what you should instead is have max-1 or max then a decrement node (–). the other thing thats kind of a n issue which prevented you from seeing the first one is you are using the equal node (==), i would instead use the less than or equal node (<=) that way if the script bug and you end up with a negative number then it will still stop creating questions.
Thank you very much, it works.
Only a last question: I have a data table with 40 elements and i would like to get 12 questions different. Now i get random questions but sometimes the following one is the same of the previous one. Can i avoid to repeat the questions?
you will need tl have an array that is either a list of questions asked or a list of available questions. to do this you could insert a script between the set node and the get datatablerow nodes. the script would be something like take current DT row variable and see if the asked questions array contains that row name, if yes then we just call the new question event and get a new question to try again, if its not contained in the array then we add it to the array and proceed.
now this is just one method and there are plenty others. for example you could on begin play load all your questions into an array then when they are used just remove the index from the array. this front loads the process so all the work is done at the start leading to better performance during the game. it also avoids the possible loop that could occur with the other method, the loop i mention is cycling though getting new questions but getting used ones over and over which is less likely the more questions you have.
As always, thanks for all your help!!!
This time, i have an infinite loop. I have integrated with those nodes as you can see in the picture. I have created also the new variable called “Question Asked”, type Name Array and i insert inside 40 elements array: from question1 to question40.
Where i’m in wrong?
i insert inside 40 elements array
what do you mean by that? are you setting the default values or something?
in any event ill post a screen shot of the second method i mentioned which will probably work better for you case since it will avoid the possibility for any loops.
so in the below method you basically create a list of all questions on construct then each time you use a question you remove it from the list. this is the opposite of the previous method where you were creating a list of used questions. ok so how this works is when the widget is created it gets all the row names of the datatable and stores them in an array, then we get a random index from that array and set it as the current row name (the one we will be using for the current question). we then remove that name from the array so it cannot be asked again. this method requires all the names to be unique (because i used the remove node) but this isnt a issue since all row names in a datatable have to be unique anyways. each time you run this script the array will become shorter, since we are using the last index which is not a set index this wont be an issue either (last index will always be recalculated when called).
hopefully that helps and gets you past the issues you were having.
It works everything!!! Thanks a lot for all your time.
below is a basic example of how i would accomplish this. first off i would be using a datatable to store all the questions and answers just to make things east to setup, modify, and track.
the first picture below shows the event graph of the widget, this is where most of the scripting happens and is where we set the images and check the answers. my method here is based on comparing images to check for the right answer but ill cover that later. first we begin by calling the get new question event (i have it set to run on construct too). then we need to figure out how many questions exist by using the get datatable row names node and the last index. remember a array begins at 0, so everything between 0 and the last index are valid questions. this is where we add in the functionality for random questions by getting a random number between 0 and last index. next we get the questions row name and set it as a variable (current DT_row). we then use that variable to get the row from the datatable. we break the result to get the images and set a variable of type slate brush for each one. we will use this variable to bind the images later. you may need to mess around with values here for height and width, i had the images set to maximize their size to the size of the button so these options dont matter. the last part of the event graph is the checking the answer on button clicked, to do this we call a function check answer which i will cover next. note the answer number int on the function this corresponds to the image and the info in the data table.
continued in next comment…