Sign in to follow this  
Followers 0
Will66

Triva Quizz

7 posts in this topic

Found the text files online that are used for a quizz bot, so thought i'd put em to use. Unzip the attached text files to the scripts directory, most questions have multiple answers. You may need to change $trivia_folder depending where you unzip them.

Was going to make it scroll up or down on a timer depending on incorrect/correct answer with maybe an explosion if you hit the bottom but moved on to something else.

hamtriviabotquestions.zip

#include <GUIConstants.au3>
#include<Array.au3>
#include<File.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Dim $this_Answer_array ;array
Dim $nextQuestion, $menuFile,$menu_text,$file_label, $Question_label,$answer_label,$answer_input,$enter_button
Dim $trivia_folder = @ScriptDir & "\hamtriviabotquestions"
Dim $gui= GUICreate("Trivia",600,600)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

buildQizzMenu()
GUISetState ()


While 1
  Sleep(10)  ; Idle around
WEnd


Func buildQizzMenu()
    Dim $FileList=_FileListToArray($trivia_folder)
    _ArraySort($FileList)
    $QuizzMenu = GUICtrlCreateMenu ("&Categories")
    For $i = 1 to $FileList[0]
        $temp=StringReplace($FileList[$i],".txt","")
        GUICtrlCreateMenuitem ($temp,$QuizzMenu)
        GUICtrlSetOnEvent(-1, "Menu_clicked")
    Next
EndFunc

Func Menu_clicked()
    $menu_text= GUICtrlRead(@GUI_CTRLID, 1)
    $menuFile = $menu_text & ".txt"
    startQuizz($menuFile) ;<==Call
EndFunc

Func startQuizz($menuFile)
    If $nextQuestion then GUICtrlDelete($nextQuestion)
    $nextQuestion=GUICtrlCreateButton("New Question",10,10)
    GUICtrlSetOnEvent($nextQuestion, "GetQuestion")
    Dim $txt_Lines
    ; Read file into array
    _FileReadToArray($trivia_folder & "\" & $menuFile,$txt_Lines)   
    $No_of_lines = $txt_Lines[0] ; number of questions in the text file
    Dim $RandNo = Random(1,$No_of_lines,1) 
    
    $Questiondata=StringSplit($txt_Lines[$RandNo],"//",1)
    $this_Answer_array=StringSplit($Questiondata[1],"/",1) ; everything before "//"
    $this_category = $this_Answer_array[2]
    $this_Question = $Questiondata[2] ; everything after "//"
    
    ;layout gui labels, buttons etc 
    If $file_label then GUICtrlDelete($file_label)
    $file_label=GUICtrlCreateLabel($menu_text & " || " & $this_category & " (" & $No_of_lines & " questions)",100,10,500)
    If $Question_label then GUICtrlDelete($Question_label)
    $Question_label=GUICtrlCreateLabel("Q. " & $this_Question,100,30,500,50)
    If $answer_label Then GUICtrlDelete($answer_label)
    $answer_label = GUICtrlCreateLabel("Answer: ", 50, 85,50,50)
    If $answer_input Then GUICtrlDelete($answer_input)
    $answer_input = GUICtrlCreateInput("", 100, 80, 180, 25)
    GUICtrlSetState ( $answer_input, $GUI_FOCUS )

    If $enter_button Then GUICtrlDelete($enter_button)
    $enter_button = GUICtrlCreateButton("Enter", 300, 80,50,25,$BS_DEFPUSHBUTTON )
                    GUICtrlSetOnEvent($enter_button, "enter_button_clicked")
                    
EndFunc

Func enter_button_clicked()
    If Not (StringLen(GUICtrlRead($answer_input)) > 0) Then Return GUICtrlSetState ( $answer_input, $GUI_FOCUS )
        Local $correct
        Dim $your_Answer=GUICtrlRead($answer_input)
        ;msgbox(0,"$this_Answer_array",$this_Answer_array[0])
        For $x = 3 to $this_Answer_array[0]
            If $your_Answer = $this_Answer_array[$x] Then $correct=$this_Answer_array[$x]           
        Next
        
            If $correct Then
                
            SoundPlay(@WindowsDir & "\media\tada.wav",1)
            
            GUICtrlSetData($answer_input,"")
            startQuizz($menuFile)
            Else
            Beep(300, 20)
            ;_ArrayDisplay($this_Answer_array,"Array")
            EndIf
    
        GUICtrlSetState ( $answer_input, $GUI_FOCUS )   
    
        
    ;MsgBox(0,"",$your_Answer)
EndFunc
    
Func GetQuestion()
    startQuizz($menuFile) ;<==Call
EndFunc

Func CLOSEClicked()
      Exit   
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nice! I like it. Here, I even created a quiz creator for it. xD

I fixed it and added to it... Also, in the Answer box, you can put, Answer1/Answer2/ect...

#include <GUIConstants.au3>

$Form1 = GUICreate("Create A Quiz", 458, 261, 193, 115)
$Label3 = GUICtrlCreateLabel("File:", 16, 8, 23, 17)
$txtFile = GUICtrlCreateInput("", 24, 32, 361, 21)
$btnBrowse = GUICtrlCreateButton("&Browse...", 392, 32, 57, 27, 0)
$Label4 = GUICtrlCreateLabel("Category:", 16, 64, 49, 17)
$txtCat = GUICtrlCreateInput("", 24, 88, 425, 21)
$Label1 = GUICtrlCreateLabel("Question:", 16, 120, 49, 17)
$txtQ = GUICtrlCreateInput("", 24, 144, 425, 21)
$Label2 = GUICtrlCreateLabel("Answer:", 16, 176, 42, 17)
$txtA = GUICtrlCreateInput("", 24, 200, 425, 21)
$btnAdd = GUICtrlCreateButton("&Add", 192, 224, 81, 33, 0)
$chkRem = GUICtrlCreateCheckbox("Remember", 45, 5)
GUICtrlSetState(-1, $GUI_CHECKED)
If FileExists(@ScriptDir&"\LastFile.Remember") Then
    $lfile = FileRead(@ScriptDir&"\LastFile.Remember")
    GUICtrlSetData($txtFile, $lfile)
EndIf
Dim $i = 1
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnAdd
            If StringLen(GUICtrlRead($txtFile)) < 3 Or StringLen(GUICtrlRead($txtCat)) < 3 Or StringLen(GUICtrlRead($txtQ)) < 3 Or StringLen(GUICtrlRead($txtA)) < 1 Then
                MsgBox(0, "Error 01", "Fill in all the required information.")
            Else
                Add()
            EndIf
        Case $btnBrowse
            Browse()
        Case $chkRem
            If $i = 1 Then
                $i = 0
            ElseIf $i = 0 Then
                $i = 1
            EndIf
    EndSwitch
WEnd
Func Add()
    Dim $File = GUICtrlRead($txtFile), $Cat = GUICtrlRead($txtCat), $Q = GUICtrlRead($txtQ), $A = GUICtrlRead($txtA)
    $Line = "/"&$Cat&"/"&$A&"//"&$Q
    FileWriteLine($File, $Line)
    If $i = 1 Then
        If FileExists(@ScriptDir&"\LastFile.Remember") Then FileDelete(@ScriptDir&"\LastFile.Remember")
        FileWrite(@ScriptDir&"\LastFile.Remember", $File)
    EndIf
    ControlSetText("", "", $txtCat, "")
    ControlSetText("", "", $txtQ, "")
    ControlSetText("", "", $txtA, "")
    ControlFocus("", "", $txtCat)
EndFunc
Func Browse()
    $File = FileSaveDialog("Save Location", @WorkingDir, "Text(*.txt)")
    If Not StringInStr($File, ".txt") Then $File = $File&".txt"
    GUICtrlSetData($txtFile, $File)
EndFunc
Edited by Joscpe

-Joscpe

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This script has potential!!!

I would do the following improvements to it:

-Some kind of image ilustrating the quiz/question

-Keep score and records

-I'll encript the file that has the questions in order to prohibit the access for the user (prevent cheating)

-Option to publish results in a web page :)

I like the idea of Joscpe the quiz creator must be a option!!!

by the way I love the script because I'm a teacher... :whistle:

Thanks for posting

Ed

Edited by Ed_Maximized

Share this post


Link to post
Share on other sites

This script has potential!!!

I would do the following improvements to it:

-Some kind of image ilustrating the quiz/question

-Keep score and records

-I'll encript the file that has the questions in order to prohibit the access for the user (prevent cheating)

-Option to publish results in a web page :)

I like the idea of Joscpe the quiz creator must be a option!!!

by the way I love the script because I'm a teacher... :whistle:

Thanks for posting

Ed

Hi everyone, glad its useful. Yep plenty of pontential to improve the gui, I was leaning towards some graphics or the like to move a submitted answer list up or down depending on the result of the answer. eg if you got an answer wrong the graphic would slide down the gui towards a fire or something or back up if you got it correct. Run an auto scroll kind of thing on a timer that scrolls down at a rate depending on a preselected level option. kind of like a tetris effect if that makes any sense.

quizz questions are from: http://www.imatowns.com/xelagot/xlgtopictrivia.html . Plenty of scope to create your own q&a or modify the array delimitors for other files.

If you spruce it up i'd love to see it.

Share this post


Link to post
Share on other sites

Nice! I like it. Here, I even created a quiz creator for it. xD

Good idea. file didn't save for me but i see the intension, even multiple answers could be added to the $txtA field by adding the delimiter between answers or even adding the whole line to the txt file in one entry eg. /category/answer1/answer2//question :whistle:

Share this post


Link to post
Share on other sites

This script has potential!!!

I would do the following improvements to it:

-Some kind of image ilustrating the quiz/question

-Keep score and records

-I'll encript the file that has the questions in order to prohibit the access for the user (prevent cheating)

-Option to publish results in a web page :)

I like the idea of Joscpe the quiz creator must be a option!!!

by the way I love the script because I'm a teacher... :whistle:

Thanks for posting

Ed

Those are greate additions. It would be very simple to keep score...

Just dim $CorrectAnswer and $WrongAnswer at the begginning and Under "Func enter_button_clicked()" change it to this:

If $correct Then
               
            SoundPlay(@WindowsDir & "\media\tada.wav",1)
            $CorrectAnswer = $CorrectAnswer + 1
           
            GUICtrlSetData($answer_input,"")
            startQuizz($menuFile)
            Else
            Beep(300, 20)
            $WrongAnswer = $WrongAnswer + 1
            ;_ArrayDisplay($this_Answer_array,"Array")
            EndIf

Oh and create a label to show right and wrong. Maby when all the questions in the quiz are finnished it has an end screen showing the resaults, an average, a percent, maby you could have an array of corrects for the levels and tell them how many guesses on each level or if they passed it? There are many things you could add to this script.


-Joscpe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0