, I’m trying to script a questions system. So I have 10 levels in my game, every level you will get a different challenge. Every level has 5 questions you have to get correct to pass to the next level. I already made ths table that includes the questions and I want to use this table to make the questions and the choices. The questions will show up on a Gui.
local Level1 = {
Question1 = {
Choice1 = "3/Correct",
Choice2 = "2/Incorrect",
Choice3 = "4/Incorrect",
Choice4 = "1/Incorrect",
Question = "How many circles were in the shapes?",
},
Question2 = {
Choice1 = "White/Correct",
Choice2 = "Green/Incorrect",
Choice3 = "Red/Incorrect",
Choice4 = "Blue/Incorrect",
Question = "What color was the squares?",
},
Question3 = {
Choice1 = "3/correct",
Choice2 = "2/Correct",
Choice3 = "4/Incorrect",
Choice4 = "1/Incorrect",
Question = "How many rectangles were in the shapes?",
},
Question4 = {
Choice1 = "White/Incorrect",
Choice2 = "Yellow/Correct",
Choice3 = "Red/Incorrect",
Choice4 = "Blue/Incorrect",
Question = "What color was the rectangles?",
},
Question5 = {
Choice1 = "11/Correct",
Choice2 = "12/Incorrect",
Choice3 = "8/Incorrect",
Choice4 = "13/Incorrect",
Question = "What was the total amount of shapes?",
},
}
How would I approach making this question system? I’m not asking for code, just how I could do this.
You said you didn’t want code so here is how I would go about making your system. First I would rewrite your question thing a bit so a question being Correct isn’t dictated by “/Correct” “/Incorrect” in the string. I would then make it so when a player reaches the end of a level they’ll press a button or something that will prompt them. This will call a function that will prompt them and wait for their response and check if they’re right or not. If they are right I’ll move on to the next question until there are no questions left. If they are wrong I’d just abort the whole process somehow, maybe destroying the GUI. Not sure if this is what you’re asking but please let me know if you need anymore help.
I could make the question system completely based on ClickDetectors and buttons. I tried using a for loop that loops through every single question table and create the UI that states the questions. The problem was i couldn’t figure out a way to stop the for loop and wait until a button is pressed then resume the loop.
That wouldn’t be the issue because I already made a string.split function that checks if the answer is correct
local function SetBool(Val)
if string.lower(Val) == "correct" then
return true
elseif string.lower(Val) == "incorrect" then
return false
end
end
Fair enough, I just find it’s generally better to not rely upon splitting and messing with strings when you have the option not to.
As for your other point, when I say wait for a response I don’t literally mean to wait. Something you could do is put all your choices into a table so you can use a for loop to loop through them and create buttons that connect to a function that can either break out of the loop or increment a variable that you can increment and call a function to prompt the next question. After that, you’d either want to delete your previous buttons or disconnect all the events. I can show you a sort of pseudo demonstration if my words aren’t making my meaning clear enough. Hope this helps, let me know if you have any more questions.
What i would do is have some sort of function whenever you need it, it would loop through the dictionary of questions, for i, fullquestion in ipairs(dict) do. Then assign the questions to variables, question = fullquestion[“Question”], A=fullquestion[“A”].split(“/“)[1] and so on. However you would ask the players to answer the question, then have a bindable event, that does nothing, maybe print something or show the player that they submitted the answer, and put a BindableEvent:Wait() function after i define all the variables. Fire the function when they submitted it. check what response they gave, and do, If response is A/B/C if func (the function that checks if its correct that you mentioned)
correct = false
if func(response) then correct =true
If response is the value, “value/Correct” then do something like this,
[details="Summary"]
correct = false
responseInLetterForm = “”
for k, v in pairs(fullquestion) do
if string.find(response, v) then
responseInLetterForm = k
break
end
if func(responseInLetterForm) then
correct = true
end
—if you’re using the func below:
if check(response) then correct = true else correct = false
—If the response is given ABCD
if check(fullquestion[response]) then correct = true else correct = false
I know you said you didn’t want code but i didn’t know how to explain it without.
I see the function that you have doesn’t work like i thought, may I offer a suggestion on another way to do it?
local function check(val)
if string.find(“Incorrect”, val) then return false else return true
end
^^ this way you can put the answer choices value in, i updated what i gave before for this question
Seems like i still misinterpreted, for this to work you would also need to change from Choice1… to ABC…
I did something simliar to what you did by adding some variables and a repeat until thing/whatever and it sort of worked
Code if you want to see it
for i,v in pairs(Level1) do
local IsActivated = false
local DidPlayerChooseRightAnswer = "Did not choose"
local UIClone = RS.UI.Choices:Clone()
UIClone.Parent = PlayerGui
for i,UI in pairs(UIClone:GetChildren()) do
UI.Text = v[UI.Name]
UI.Position = UDim2.new(GetUdimUnseen(UI))
UI:TweenPosition(UDim2.new(GetUdimSeen(UI)), "Out", "Quart", 0.8)
if UI:IsA("GuiButton") then
UI.Text = string.split(v[UI.Name], "/")[1]
UI.IsCorrect.Value = SetBool(string.split(v[UI.Name], "/")[2])
local Conn
Conn = UI.Activated:Connect(function()
print("Activated")
if UI.IsCorrect.Value == true then
IsActivated = true
DidPlayerChooseRightAnswer = "right"
UIClone:Destroy()
else
DidPlayerChooseRightAnswer = "wrong"
RS.Remotes.EndLevel:FireServer()
UIClone:Destroy()
Conn:Disconnect()
end
end)
end
end
repeat wait() until IsActivated == true or DidPlayerChooseRightAnswer == "wrong"
IsActivated = false
if DidPlayerChooseRightAnswer == "wrong" then
break
end
end