Jump to content

Need some direction for Riddle GUI


Recommended Posts

My friends birthday is coming up and this kid loves riddles and mysteries. I want to make a program that has various riddles and as he gets each one right the GUI changes to give hints at the answer to the riddles and at the end give him a password to open up another program created in autoit with directions to get his birthday present.

I've never created a GUI and I would love if I could get some assistance. I have most of the riddles already made, just not sure how to implement them.

I would like for the GUI to show the actual riddle in the middle or top and then have three buttons that when pressed bring up hints to the answer in a MSGBOX or within the actual GUI.  On the bottom there would need to be an input area that allows the program to check his input to the correct answer and once he does get the correct answer the GUI would need to change over to the next riddle. I certainly don't expect anyone to write this for me, but I would love if you could point me in the right direction to get started!

Link to comment
Share on other sites

Sounds like an ideal project for you to learn AutoIt. Here is a list of functions that come to mind.

GUICreate
GUISetState
GUIGetMsg
GUICtrlSetOnEvent
GUISetOnEvent
GUICtrlCreateLabel
GUICtrlCreateButton

; Actually look at GUI management in the help file.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Zeerti,

That was a bit of fun. :D

Create an ini file like this and save it as "Riddles.ini" in the same folder as the script:

[1]
Riddle=Riddle 1
Answer=Answer 1
Hint_1=Hint 11
Hint_2=Hint 12
Hint_3=Hint 13
[2]
Riddle=Riddle 2
Answer=Answer 2
Hint_1=Hint 21
Hint_2=Hint 22
Hint_3=Hint 23
[3]
Riddle=Riddle 3
Answer=Answer 3
Hint_1=Hint 31
Hint_2=Hint 32
Hint_3=Hint 33

Then run this script and you should get something close to what you want:

#include <GUIConstantsEx.au3>

Global $aButton[3], $aHint_Label[3]
Global $iRiddle = 1, $sRiddle, $sAnswer, $aHint[3]
Global $sRiddles = @ScriptDir & "\Riddles.ini"
Global $iSkip = 0

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xFFCCCC)

$cRiddle_Label = GUICtrlCreateLabel("The riddle will appear here", 10, 10, 480, 100)
GUICtrlSetFont(-1, 24)
GUICtrlSetBkColor(-1, 0xCCFFCC)

For $i = 0 To 2
    $aButton[$i] = GUICtrlCreateButton("Hint " & $i + 1, 15 + (165 * $i), 120, 145, 30)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $aHint_Label[$i] = GUICtrlCreateLabel("Hints appear here", 15 + (165 * $i), 180, 145, 100)
    GUICtrlSetBkColor(-1, 0xCCCCFF)
Next

$cAnswer = GUICtrlCreateInput("Enter your answer here", 10, 300, 480, 100)
GUICtrlSetFont(-1, 18)
GUICtrlSetBkColor(-1, 0xCCFFFF)

$cButton_Check = GUICtrlCreateButton("Start", 10, 420, 230, 60)
GUICtrlSetState(-1, $GUI_FOCUS)
$cButton_Skip = GUICtrlCreateButton("Skip Current Riddle", 260, 420, 230, 60)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Check
            If GUICtrlRead($cButton_Check) = "Start" Then
                GUICtrlSetData($cButton_Check, "Check Answer")
                $iRiddle = _Load_Riddle($iRiddle)
                _Show_Riddle()
            Else
                If GUICtrlRead($cAnswer) = $sAnswer Then
                    MsgBox(0, "Congrats", "Correct answer")
                    $iRiddle = _Load_Riddle($iRiddle)
                    If $iRiddle Then
                        _Show_Riddle()
                    Else
                        MsgBox(0, "Hi", "Now we show the directions GUI")
                    EndIf
                Else
                    MsgBox(0, "Sorry", "Not correct - try again")
                EndIf
            EndIf
        Case $cButton_Skip
            If MsgBox(1, "Really?", "You only get 2 chances to skip a riddle!") = 1 Then
                $iSkip += 1
                If $iSkip = 2 Then
                    GUICtrlSetState($cButton_Skip, $GUI_DISABLE)
                EndIf
                MsgBox(0, "Correct Answer", $sAnswer)
                $iRiddle = _Load_Riddle($iRiddle)
                If $iRiddle Then
                    _Show_Riddle()
                Else
                    MsgBox(0, "Hi", "Now we show the directions GUI")
                EndIf
            EndIf
        Case Else
            For $i = 0 To 2
                If $iMsg = $aButton[$i] Then
                    GUICtrlSetState($aHint_Label[$i], $GUI_SHOW)
                    GUICtrlSetState($aButton[$i], $GUI_DISABLE)
                    If $i < 2 Then
                        GUICtrlSetState($aButton[$i + 1], $GUI_ENABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next

    EndSwitch

WEnd

Func _Show_Riddle()

    GUICtrlSetData($cRiddle_Label, $sRiddle)
    GUICtrlSetData($cAnswer, "")
    For $i = 0 To 2
        GUICtrlSetData($aHint_Label[$i], $aHint[$i])
        GUICtrlSetState($aHint_Label[$i], $GUI_HIDE)
        GUICtrlSetState($aButton[$i], $GUI_DISABLE)
    Next
    GUICtrlSetState($aButton[0], $GUI_ENABLE)

EndFunc

Func _Load_Riddle($iIndex)

    $sRiddle = IniRead($sRiddles, $iIndex, "Riddle", "Error")
    $sAnswer = IniRead($sRiddles, $iIndex, "Answer", "Error")
    $aHint[0] = IniRead($sRiddles, $iIndex, "Hint_1", "Error")
    $aHint[1] = IniRead($sRiddles, $iIndex, "Hint_2", "Error")
    $aHint[2] = IniRead($sRiddles, $iIndex, "Hint_3", "Error")

    If $sRiddle <> "Error" Then
        Return $iIndex + 1
    Else
        Return 0
    EndIf

EndFunc

As you are getting a complete freebie solution, I have deliberately left out all comments so you have to work a bit to refine the script. But if you do get stuck, please do ask. ;)

I hope your friend enjoys his present. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Zeerti,

That was a bit of fun. :D

Create an ini file like this and save it as "Riddles.ini" in the same folder as the script:

[1]
Riddle=Riddle 1
Answer=Answer 1
Hint_1=Hint 11
Hint_2=Hint 12
Hint_3=Hint 13
[2]
Riddle=Riddle 2
Answer=Answer 2
Hint_1=Hint 21
Hint_2=Hint 22
Hint_3=Hint 23
[3]
Riddle=Riddle 3
Answer=Answer 3
Hint_1=Hint 31
Hint_2=Hint 32
Hint_3=Hint 33

Then run this script and you should get something close to what you want:

#include <GUIConstantsEx.au3>

Global $aButton[3], $aHint_Label[3]
Global $iRiddle = 1, $sRiddle, $sAnswer, $aHint[3]
Global $sRiddles = @ScriptDir & "\Riddles.ini"
Global $iSkip = 0

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xFFCCCC)

$cRiddle_Label = GUICtrlCreateLabel("The riddle will appear here", 10, 10, 480, 100)
GUICtrlSetFont(-1, 24)
GUICtrlSetBkColor(-1, 0xCCFFCC)

For $i = 0 To 2
    $aButton[$i] = GUICtrlCreateButton("Hint " & $i + 1, 15 + (165 * $i), 120, 145, 30)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $aHint_Label[$i] = GUICtrlCreateLabel("Hints appear here", 15 + (165 * $i), 180, 145, 100)
    GUICtrlSetBkColor(-1, 0xCCCCFF)
Next

$cAnswer = GUICtrlCreateInput("Enter your answer here", 10, 300, 480, 100)
GUICtrlSetFont(-1, 18)
GUICtrlSetBkColor(-1, 0xCCFFFF)

$cButton_Check = GUICtrlCreateButton("Start", 10, 420, 230, 60)
GUICtrlSetState(-1, $GUI_FOCUS)
$cButton_Skip = GUICtrlCreateButton("Skip Current Riddle", 260, 420, 230, 60)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Check
            If GUICtrlRead($cButton_Check) = "Start" Then
                GUICtrlSetData($cButton_Check, "Check Answer")
                $iRiddle = _Load_Riddle($iRiddle)
                _Show_Riddle()
            Else
                If GUICtrlRead($cAnswer) = $sAnswer Then
                    MsgBox(0, "Congrats", "Correct answer")
                    $iRiddle = _Load_Riddle($iRiddle)
                    If $iRiddle Then
                        _Show_Riddle()
                    Else
                        MsgBox(0, "Hi", "Now we show the directions GUI")
                    EndIf
                Else
                    MsgBox(0, "Sorry", "Not correct - try again")
                EndIf
            EndIf
        Case $cButton_Skip
            If MsgBox(1, "Really?", "You only get 2 chances to skip a riddle!") = 1 Then
                $iSkip += 1
                If $iSkip = 2 Then
                    GUICtrlSetState($cButton_Skip, $GUI_DISABLE)
                EndIf
                MsgBox(0, "Correct Answer", $sAnswer)
                $iRiddle = _Load_Riddle($iRiddle)
                If $iRiddle Then
                    _Show_Riddle()
                Else
                    MsgBox(0, "Hi", "Now we show the directions GUI")
                EndIf
            EndIf
        Case Else
            For $i = 0 To 2
                If $iMsg = $aButton[$i] Then
                    GUICtrlSetState($aHint_Label[$i], $GUI_SHOW)
                    GUICtrlSetState($aButton[$i], $GUI_DISABLE)
                    If $i < 2 Then
                        GUICtrlSetState($aButton[$i + 1], $GUI_ENABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next

    EndSwitch

WEnd

Func _Show_Riddle()

    GUICtrlSetData($cRiddle_Label, $sRiddle)
    GUICtrlSetData($cAnswer, "")
    For $i = 0 To 2
        GUICtrlSetData($aHint_Label[$i], $aHint[$i])
        GUICtrlSetState($aHint_Label[$i], $GUI_HIDE)
        GUICtrlSetState($aButton[$i], $GUI_DISABLE)
    Next
    GUICtrlSetState($aButton[0], $GUI_ENABLE)

EndFunc

Func _Load_Riddle($iIndex)

    $sRiddle = IniRead($sRiddles, $iIndex, "Riddle", "Error")
    $sAnswer = IniRead($sRiddles, $iIndex, "Answer", "Error")
    $aHint[0] = IniRead($sRiddles, $iIndex, "Hint_1", "Error")
    $aHint[1] = IniRead($sRiddles, $iIndex, "Hint_2", "Error")
    $aHint[2] = IniRead($sRiddles, $iIndex, "Hint_3", "Error")

    If $sRiddle <> "Error" Then
        Return $iIndex + 1
    Else
        Return 0
    EndIf

EndFunc

As you are getting a complete freebie solution, I have deliberately left out all comments so you have to work a bit to refine the script. But if you do get stuck, please do ask. ;)

I hope your friend enjoys his present. :)

M23

 

Well for starters I am plum confused why you made an .INI File for this. I know a lot of the basics to general programming, but I've never delved in that kind of thing before. What is the purpose of the ini file?

Link to comment
Share on other sites

  • Moderators

Zeerti,

As you can see, the ini file holds the riddles and their answers and hints so that they can be read into the script. It is just one way of doing it - you could hard code the data into arrays within the script itself if you so desired. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Zeerti,

The advantage of this approach is that you can use the same script with different sets of information in the ini file. A disadvantage is that you need 2 files - the script and the ini - although you can get round that by using FileInstall to hide the ini within the compiled executable. :)

Basically we can look to Kipling for the answer - you choose the one that works and which suits you best! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Some of my riddles are longer than the area provided in the script you posted. How does one change the font size or append a scroll bar? I have made the window larger than the original.

Second, I found it interesting that you used a loop to create the buttons, brilliant! However I am having some issues getting them moved to the proper place due to not understanding the loop. Could you elaborate?

I've never used case before, what exactly is that doing? Is that what is allowing for each riddle to be transposed to the GUI? Like each instance of it should I say.

Is there a simpler way to set the buttons where you want them instead of guessing and checking a whole lot? 

Edited by Zeerti
Link to comment
Share on other sites

 

Is this a preferable way to do this?

 

Yes, in general, using the code Melba provides is the preferred method for AutoIt-ing.

and running through the GuiCtrlSet* portion of the help file will assist with manipulating the data, to include font.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

Zeerti,

I did tell you you were going to have to learn a little! :D

 

You can change the font size by amending the GUICtrlSetFont lines - the -1 refers to the last created control, so do not touch that! If you want a scrollbar than I suggest you use an Edit control - you would need to use GUICtrlCreateEdit in place of GUICtrlCreateLabel. But you might want to set the $ES_READONLY style if you were to do that. ;)

The loop uses a simple alogorithm (15 + (165 * $i)) to increase the X-coordinate of the button on each pass - it gives 15, 180, 345 as it runs through. So you will need to work out where you want the buttons to appear and then adjust the algorithm accordingly.

Case is used in Select & Switch structures. These are very useful to replace multiple If...Then structures - as you can see. Look in the Help file to see how they work. In this script they are used to fire code depending on the control activated and detected by GUIGetMsg.

I hope that helps. Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at this excellent tutorial. AutoIt syntax is not difficult, but like all things to do with computers you have to get it just right. ;)

boththose,

I am flattered - thank you. :>

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...