• DCheckBox help.
    2 replies, posted
Hey, I have been working with the DCheckBox VGUI element recently and have ran into an issue where I am creating each DCheckBox through a for loop and this creates four check boxes and I need it so if you click on one of the check boxes it will deselect the others since this is for an exam system and need it so that for each question there can only be one selected answer.The reason each answer is loaded through the table is as it should randomly select the order the answers are spawned it. Another reason I am finding this difficult is due to the fact the check boxes are created in a for loop meaning I am finding it hard to go back and do something with the element. local questionNumber = 0 local questionsInTable = {} while questionNumber < 4 do local generatedNumber = math.Rand(1, 4) generatedNumber = math.Round(generatedNumber) if generatedNumber < 1 then continue end if generatedNumber > 4 then continue end if questionsInTable[generatedNumber] then continue end questionsInTable[generatedNumber] = {} questionTickBox = vgui.Create('DCheckBox', questionPanel) questionTickBox:SetSize(ScrH() * 0.02, ScrH() * 0.02) questionTickBox:SetPos(ScrW() * 0.005, (ScrH() * 0.03) + (questionNumber * (ScrH() * 0.025))) function questionTickBox:OnChange(state) print(generatedNumber .. ') ' .. questionInfo.possibleAnswers[generatedNumber] .. ' / Was selected') if not self then if questionTickBox:GetChecked() then questionTickBox:SetValue(false) end end end local answerDisplay = vgui.Create('DPanel', questionPanel) answerDisplay:SetSize(ScrW() * 0.45, ScrH() * 0.02) answerDisplay:SetPos(ScrW() * 0.02, (ScrH() * 0.03) + (questionNumber * (ScrH() * 0.025))) function answerDisplay:Paint(_, h) draw.SimpleText(questionInfo.possibleAnswers[generatedNumber], 'LRP-Licence-System-Medium-Font', 0, h / 2, lrpWhite, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER) end questionNumber = questionNumber + 1 end Thanks for reading and I hope one of you are able to assist me in making it so only one check box can be selected at a time.
This while loop... All you have to do is just store them in a table and do a for loop. I hope it's not a paid job. https://pastebin.com/raw/3axCWYek
Thanks for the help and this was not a paid job, just needed some help on a project I was workig on.
Sorry, you need to Log In to post a reply to this thread.