Sign in to follow this  
Followers 0
Damein

Not sure how to phrase title..

9 posts in this topic

So I am making flash memory game where it displays a certain number of colors per level and you must put them in the sequence they were shown.

I have them stored in an ini like so:

[Easy]

1=1

2=1|1

3=1|1|4

4=1|1|4|3

5=1|1|4|3|1

and so on until the last one has 20 digits, each one will be the same, save for the last digit.

Now, I can display these digits by doing a:

$IniReadVar = IniReadSection

And then:

$IniReadVarSplit = StringSplit($IniReadVar, "|")

Which will create an array of IniReadVarSplit[0]-[20].

And then I proceed by:

If $IniReadyVarSplit[1] = 1 Then

(Show the first number in the sequence)

And then continue on for each level, but thats a lot of code that I think can be shortened.

If this is not clear I will post me script later, but its on another computer and its really sloppy right now.

Once this is cleared up I have another dilemma I can't get under control :)

Thanks in advance!


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



Damein,

If all the strings are the same bar the final character, then you only need to store the final 20-digit version and then just read the first X digits depending on the level. That way you save a lot of typing in the ini.

You will need to use StringSplit to get an array of the content (as you already do) and then a For...Next loop with a variable index to get at the digits you require for each level. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hmm, thats true.

Although, I'm still not 100% how I would implement the numbers efficiently for what else I need.

I need each number to be saved into a var so I can check if the user inputs the correct numbers, in the correct order.

For example, I could use a For loop to display each number, that parts simple.

But after I display each number, I next have to have the user input the same numbers, in the same sequence in order to pass.

So my question I guess is how would I compare the user input (This will be via clicking 1 of 4 buttons, correspondingly) to the For loops displays?


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Damein,

Run a loop to collect the user inputs into an array and then compare the 2 arrays. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So I tried what you said about the user inputs, but I could not get the _ArraySearch to come up with a valid entry when there are more than 1 inputs, no matter what I tried :)

I found a way to do the inputs, but I think it could easily be shortened if I could get _ArraySearch to work properly.

Here is the script in full.

(If you scroll down to the Input() function you will see where I am doing the checking.)

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiButton.au3>
#include <File.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)

Global $Gui, $ChosenColor2, $AnswerCheck, $Blue, $Green, $Red, $Purple, $SleepTime, $ButtonPressed, $Var, $ColorArray, $1, $2, $3, $4, $TrimedColors, $NumberOfButtons, $TrimedColorsSplit, $Button, $CorrectNumber, $Button1, $Button2, $CorrectAnswer, $ButtonCount, $CheckingAnswer, $DoNotRepeatArrayToString, $Var2, $Answer1Found, $TestSleep
$CurrentLevel = 1

Local $ColorArray[21], $Button[21], $ButtonList[21]
For $i = 0 To 19 Step +1
_ArrayDelete($ButtonList, $i)
Next

$File = "Colors.ini"

FileDelete($File)

Intro()

Func Intro()
    _GDIPlus_Startup ()
    $hPen = _GDIPlus_PenCreate ()
    $GUI = GUICreate("Flash Memory", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($GUI)
    $FadedBlue = GuiCtrlCreatePic("Imgs\FadedBlue.bmp", 2,2,146,146)
    $FadedGreen = GuiCtrlCreatePic("Imgs\FadedGreen.bmp", 153,2,145,146)
    $FadedRed = GuiCtrlCreatePic("Imgs\FadedRed.bmp", 2,153,145,145)
    $FadedPurple = GuiCtrlCreatePic("Imgs\FadedPurple.bmp", 153,153,145,145)
    GUISetState()
    _GDIPlus_GraphicsDrawLine ($hGraphic, 0, 150, 300, 150, $hPen)
    _GDIPlus_GraphicsDrawLine ($hGraphic, 150, 0, 150, 300, $hPen)
    $hBrush = _GDIPlus_BrushCreateSolid (0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Chiller")
    $hFont = _GDIPlus_FontCreate ($hFamily, 35, 1)
    $tLayout = _GDIPlus_RectFCreate (0, 0, 300, 300)
    
    For $Count = 0 To 5 Step +1
        GuiCtrlSetImage($FadedBlue, "Imgs\Blue.bmp",-1)
        Sleep(40)
        GUICtrlSetImage($FadedBlue, "Imgs\FadedBlue.bmp", -1)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
        Sleep(40)
        GUICtrlSetImage($FadedGreen, "Imgs\Green.bmp", -1)
        Sleep(40)
        GUICtrlSetImage($FadedGreen, "Imgs\FadedGreen.bmp", -1)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
        Sleep(40)
        GUICtrlSetImage($FadedRed, "Imgs\Red.bmp", -1)
        Sleep(40)
        GUICtrlSetImage($FadedRed, "Imgs\FadedRed.bmp", -1)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF &  "       game!", $hFont, $tLayout, $hFormat, $hBrush)
        Sleep(40)
        GUICtrlSetImage($FadedPurple, "Imgs\Purple.bmp", -1)
        Sleep(40)
        GUICtrlSetImage($FadedPurple, "Imgs\FadedPurple.bmp", -1)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF &  "       game!", $hFont, $tLayout, $hFormat, $hBrush)
    Next
    
        For $Count = 0 To 5 Step +1
            GUICtrlSetImage($FadedPurple, "Imgs\Purple.bmp", -1)
            Sleep(40)
            GUICtrlSetImage($FadedPurple, "Imgs\FadedPurple.bmp", -1)
            _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
            Sleep(40)
            GUICtrlSetImage($FadedRed, "Imgs\Red.bmp", -1)
            Sleep(40)
            GUICtrlSetImage($FadedRed, "Imgs\FadedRed.bmp", -1)
            _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
            Sleep(40)
            GUICtrlSetImage($FadedGreen, "Imgs\Green.bmp", -1)
            Sleep(40)
            GUICtrlSetImage($FadedGreen, "Imgs\FadedGreen.bmp", -1)
            _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
            Sleep(40)
            GuiCtrlSetImage($FadedBlue, "Imgs\Blue.bmp",-1)
            Sleep(40)
            GUICtrlSetImage($FadedBlue, "Imgs\FadedBlue.bmp", -1)
            _GDIPlus_GraphicsDrawStringEx ($hGraphic, "  Welcome to the" & @CRLF & "   Flash Memory" & @CRLF & "       game!", $hFont, $tLayout, $hFormat, $hBrush)
            Sleep(40)
        Next
    GuiDelete($Gui)
        _GDIPlus_Startup ()
    $hPen = _GDIPlus_PenCreate ()
    $GUI = GUICreate("Flash Memory", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($GUI)
    $EasyButton = GuiCtrlCreateButton("Easy", 2, 2, 146, 146, $BS_BITMAP)
    GUICtrlSetImage($EasyButton, "Imgs\EasyImage.bmp", 1)
    GUICtrlSetOnEvent($EasyButton, "Easy")
    $MediumButton = GuiCtrlCreateButton("Medium", 153, 2, 145, 146, $BS_BITMAP)
    GUICtrlSetImage($MediumButton, "Imgs\MediumImage.bmp", 1)
    GUICtrlSetOnEvent($MediumButton, "Medium")
    $HardButton = GuiCtrlCreateButton("Hard", 2, 153, 145, 146, $BS_BITMAP)
    GUICtrlSetImage($HardButton, "Imgs\HardImage.bmp", 1)
    GUICtrlSetOnEvent($HardButton, "Hard")
    $ExpertButton = GuiCtrlCreateButton("Expert", 153, 153, 145, 145, $BS_BITMAP)
    GUICtrlSetImage($ExpertButton, "Imgs\ExpertImage.bmp", 1)
    GUICtrlSetOnEvent($ExpertButton, "Expert")
    GUISetState()
    _GDIPlus_GraphicsDrawLine ($hGraphic, 0, 150, 300, 150, $hPen)
    _GDIPlus_GraphicsDrawLine ($hGraphic, 150, 0, 150, 300, $hPen)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
EndFunc

Func CloseGUI()
    Exit
EndFunc

Func Easy()
    GuiDelete($Gui)
    $hPen = _GDIPlus_PenCreate ()
    $GUI = GUICreate("Flash Memory", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($GUI)
    $1 = GuiCtrlCreateButton("Blue", 2, 2, 146, 146, $BS_BITMAP)
    GUICtrlSetImage($1, "Imgs\FadedBlue.bmp", 1)
    GUICtrlSetOnEvent($1, "Blue")
    $2 = GuiCtrlCreateButton("Green", 153, 2, 145, 146, $BS_BITMAP)
    GUICtrlSetImage($2, "Imgs\FadedGreen.bmp", 1)
    GUICtrlSetOnEvent($2, "Green")
    $3 = GuiCtrlCreateButton("Red", 2, 153, 145, 146, $BS_BITMAP)
    GUICtrlSetImage($3, "Imgs\FadedRed.bmp", 1)
    GUICtrlSetOnEvent($3, "Red")
    $4 = GuiCtrlCreateButton("Purple", 153, 153, 145, 145, $BS_BITMAP)
    GUICtrlSetImage($4, "Imgs\FadedPurple.bmp", 1)
    GUICtrlSetOnEvent($4, "Purple")
    GUISetState()
    _GDIPlus_GraphicsDrawLine ($hGraphic, 0, 150, 300, 150, $hPen)
    _GDIPlus_GraphicsDrawLine ($hGraphic, 150, 0, 150, 300, $hPen)
    $DifficultySetting = 1
    $TestSleep = "200"
    _GDIPlus_PenDispose ($hPen)
    _GDIPlus_Shutdown ()
    
    For $Count = 1 To 20 Step +1
    $Color = Round(Random(1,4))
    $ColorArray[$Count] = $Color
Next
_ArrayDelete($ColorArray, 0)
$Var = _ArrayToString($ColorArray, "")
    EasyGame()
EndFunc

Func EasyGame()
    While $CheckingAnswer = 1
        Input()
        WEnd
    If $CurrentLevel = 1 Then
        $TrimedColors = StringTrimRight($Var, 19)
        For $Count = 1 To $CurrentLevel Step +1
            If $TrimedColors = 1 Then
                GUICtrlSetImage($1, "Imgs\Blue.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($1, "Imgs\FadedBlue.bmp", 1)
            EndIf
            If $TrimedColors = 2 Then
                GUICtrlSetImage($2, "Imgs\Green.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($2, "Imgs\FadedGreen.bmp", 1)
            EndIf
            If $TrimedColors = 3 Then
                GUICtrlSetImage($3, "Imgs\Red.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($3, "Imgs\FadedRed.bmp", 1)
            EndIf
            If $TrimedColors = 4 Then
                GUICtrlSetImage($4, "Imgs\Purple.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($4, "Imgs\FadedPurple.bmp", 1)
            EndIf
        Next
        Sleep($TestSleep)
        $CheckingAnswer = 1
    EndIf
    If $CurrentLevel = 2 Then
        $TrimedColors = StringTrimRight($Var, 18)
        $TrimedColorsSplit = StringSplit($TrimedColors, "")
        For $Count = 1 To $CurrentLevel Step +1
            If $TrimedColorsSplit[$Count] = 1 Then
                GUICtrlSetImage($1, "Imgs\Blue.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($1, "Imgs\FadedBlue.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 2 Then
                GUICtrlSetImage($2, "Imgs\Green.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($2, "Imgs\FadedGreen.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 3 Then
                GUICtrlSetImage($3, "Imgs\Red.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($3, "Imgs\FadedRed.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 4 Then
                GUICtrlSetImage($4, "Imgs\Purple.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($4, "Imgs\FadedPurple.bmp", 1)
                Sleep($TestSleep)
            EndIf
        Next
        Sleep($TestSleep)
        $CheckingAnswer = 1
    EndIf   
    If $CurrentLevel = 3 Then
        $TrimedColors = StringTrimRight($Var, 17)
        $TrimedColorsSplit = StringSplit($TrimedColors, "")
        For $Count = 1 To $CurrentLevel Step +1
            If $TrimedColorsSplit[$Count] = 1 Then
                GUICtrlSetImage($1, "Imgs\Blue.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($1, "Imgs\FadedBlue.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 2 Then
                GUICtrlSetImage($2, "Imgs\Green.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($2, "Imgs\FadedGreen.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 3 Then
                GUICtrlSetImage($3, "Imgs\Red.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($3, "Imgs\FadedRed.bmp", 1)
                Sleep($TestSleep)
            EndIf
            If $TrimedColorsSplit[$Count] = 4 Then
                GUICtrlSetImage($4, "Imgs\Purple.bmp", 1)
                Sleep($TestSleep)
                GUICtrlSetImage($4, "Imgs\FadedPurple.bmp", 1)
                Sleep($TestSleep)
            EndIf
        Next
        Sleep($TestSleep)
    EndIf
    EndFunc

Func Medium()
    $DifficultySetting = 2
EndFunc

Func Hard()
    $DifficultySetting = 3
EndFunc

Func Expert()
    $DifficultySetting = 4
EndFunc

Func Input()
        If $CurrentLevel = 1 Then
            $TrimedColors2 = StringTrimRight($Var, 19)
            $iKeyIndex = _ArrayBinarySearch($ButtonList, $TrimedColors2, 1)
            If Not @error Then
            $CurrentLevel += 1
            EasyGame()
            Else
            Sleep(10)
            EndIf
        EndIf
        If $CurrentLevel = 2 Then
            If $CheckingAnswer = 1 Then
                Sleep(10)
            Else
            $Var2 = _ArrayToString($ButtonList,",")
        EndIf
        If StringLen($Var2) > 4 Then
            $TrimedColors2 = StringTrimRight($Var, 18)
            $TrimedButtons = StringTrimLeft($Var2, 1)
            $SplitTrimedColors2 = StringSplit($TrimedColors2,"")
            $SplitTrimedButtons = StringSplit($TrimedButtons,",")
            If $SplitTrimedColors2[1] = $SplitTrimedButtons[1] Then
            $Answer1Found = 1
        Else
            MsgBox(0, "Test", "Not found 1")
        EndIf
        If $Answer1Found = 1 Then
            If $SplitTrimedColors2[2] = $SplitTrimedButtons[3] Then
            $CurrentLevel += 1
            EasyGame()
            Else
            MsgBox(0, "Test", "Not found 2")
        EndIf
        EndIf
        Else
            Sleep(10)
        EndIf
    EndIf
            If $CurrentLevel = 3 Then
            If $CheckingAnswer = 1 Then
                Sleep(10)
            Else
            $Var2 = _ArrayToString($ButtonList,",")
        EndIf
        If StringLen($Var2) > 11 Then
            $TrimedColors2 = StringTrimRight($Var, 17)
            MsgBox(0, "TrimedColors2", $TrimedColors2)
            $TrimedButtons = StringTrimLeft($Var2, 7)
            MsgBox(0, "TrimedButtons", $TrimedButtons)
            $SplitTrimedColors2 = StringSplit($TrimedColors2,"")
            $SplitTrimedButtons = StringSplit($TrimedButtons,",")
            If $SplitTrimedColors2[1] = $SplitTrimedButtons[1] Then
            $Answer1Found = 1
        Else
            MsgBox(0, "Test", "Not found 1")
        EndIf
        If $Answer1Found = 1 Then
            MsgBox(0, "test", $SplitTrimedColors2[2] & @CRLF & $SplitTrimedButtons[2])
            If $SplitTrimedColors2[2] = $SplitTrimedButtons[2] Then
                $Answer1Found = 2
            Else
            MsgBox(0, "test", "Not found 2")
        EndIf
        If $Answer1Found = 2 Then
            If $SplitTrimedColors2[3] = $SplitTrimedButtons[3] Then
            $CurrentLevel += 1
            EasyGame()
            Else
            MsgBox(0, "Test", "Not found 3")
        EndIf
        EndIf
        EndIf
        Else
            Sleep(10)
        EndIf
        EndIf
    EndFunc

Func Blue()
    $CheckingAnswer = 0
    $ButtonCount += 1
    _ArrayInsert($ButtonList, $ButtonCount, "1")
    Input()
EndFunc

Func Green()
    $CheckingAnswer = 0
    $ButtonCount += 1
    _ArrayInsert($ButtonList, $ButtonCount, "2")
    Input()
EndFunc

Func Red()
    $CheckingAnswer = 0
    $ButtonCount += 1
    _ArrayInsert($ButtonList, $ButtonCount, "3")
    Input()
EndFunc

Func Purple()
    $CheckingAnswer = 0
    $ButtonCount += 1
    _ArrayInsert($ButtonList, $ButtonCount, "4")
    Input()
EndFunc

Func _Sleep()
    If $NumberOfButtons = 1 Then
        Sleep(10)
    EndIf
    EndFunc

    

While 1
    Sleep(10)
    WEnd

Thanks for your help Melba :)

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Damein,

Nothng personal, but that code is so screwed up I am having real trouble fathoming out how it is supposed to work, let alone debugging it. :)

For a start you are going to run into serious recursion problems. You are calling function Input from within function EasyGame and then recalling EasyGame from within Input! You will crash your machine very easily if you code like this - take a look at the Recursion tutorial in the Wiki if you want to know more about recursion and why you should avoid it. :P

Then there are any number of peculiar code snippets - here are few that I picked out:

- You declare $ButtonList[21] and then promptly use a loop to _ArrayDelete 20 of the elements - why not just declare the array with a single element?

- You define a filename in $File and then promptly delete it without ever referring to it again. :)

- You create an array $ColorArray which you then immediately transform into a string - why not create it as a string to begin with?

- You really need to look at Switch and Select structures - multiple If...EndIf structures are very definitely not the way to go. :D

I am going to see if I can come up with a script which does what you want in simplifed form so that you can use it as a template for bigger and better things. But do not hold your breath - it might take a while as I try to understand what you want to do! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Damein,

Here is my version of how I think you want your script to run. Every function finishes and returns to the idle loop so that you do not have a recursion problem. Take a look and see if it does what you want - note that it shows the colours in text in the SciTE console as I do not have the correct images: :)

#include <GuiConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $Gui, $CheckingAnswer = 0, $sUserAnswer = "", $CurrentLevel = 1, $Var, $fGame = ""

Intro()

While 1

    ; We wait until a game has been chosen
    If $CheckingAnswer = 0 Then
        Switch $fGame
            Case "Easy"
                EasyGame()
            ;Case "Medium"
            ; and so on
        EndSwitch
    EndIf

    Sleep(10)
WEnd

Func Intro()

    $Gui = GUICreate("Flash Memory", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    $EasyButton = GUICtrlCreateButton("Easy", 2, 2, 146, 146)
    GUICtrlSetOnEvent($EasyButton, "Easy")
    $MediumButton = GUICtrlCreateButton("Medium", 153, 2, 145, 146)
    ;GUICtrlSetOnEvent($MediumButton, "Medium")
    $HardButton = GUICtrlCreateButton("Hard", 2, 153, 145, 146)
    ;GUICtrlSetOnEvent($HardButton, "Hard")
    $ExpertButton = GUICtrlCreateButton("Expert", 153, 153, 145, 145)
    ;GUICtrlSetOnEvent($ExpertButton, "Expert")
    GUISetState()

EndFunc

Func Easy()
    GUIDelete($Gui)
    $Gui = GUICreate("Flash Memory", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    $1 = GUICtrlCreateButton("Blue", 2, 2, 146, 146)
    GUICtrlSetOnEvent($1, "Blue")
    $2 = GUICtrlCreateButton("Green", 153, 2, 145, 146)
    GUICtrlSetOnEvent($2, "Green")
    $3 = GUICtrlCreateButton("Red", 2, 153, 145, 146)
    GUICtrlSetOnEvent($3, "Red")
    $4 = GUICtrlCreateButton("Purple", 153, 153, 145, 145)
    GUICtrlSetOnEvent($4, "Purple")
    GUISetState()
    $DifficultySetting = 1
    $TestSleep = "200"

    $Var = ""
    For $i = 1 To 20
        $Var &= Random(1, 4, 1)
    Next

    ConsoleWrite($Var & @CRLF & @CRLF) ; Just for testing

    ; Set a flag to show which game to play
    $fGame = "Easy"

EndFunc   ;==>Easy


Func EasyGame()

    ; Display the required number of colours - the number increases automatically with $CurrentLevel
    For $i = 1 To $CurrentLevel
        ; Extract the colour from the list
        $iCurrentColor = StringMid($Var, $i, 1)
        ; Display the colour in the right place
        Switch $iCurrentColor
            Case 1
                ConsoleWrite("Blue" & @CRLF) ; I do not have the images so this will tell you in the console what they colours shown were
                ;GUICtrlSetImage($1, "Imgs\Blue.bmp", 1)
                ;Sleep($TestSleep)
                ;GUICtrlSetImage($1, "Imgs\FadedBlue.bmp", 1)
            Case 2
                ConsoleWrite("Green" & @CRLF)
                ;GUICtrlSetImage($2, "Imgs\Green.bmp", 1)
                ;Sleep($TestSleep)
                ;GUICtrlSetImage($2, "Imgs\FadedGreen.bmp", 1)
            Case 3
                ConsoleWrite("Red" & @CRLF)
                ;GUICtrlSetImage($3, "Imgs\Red.bmp", 1)
                ;Sleep($TestSleep)
                ;GUICtrlSetImage($3, "Imgs\FadedRed.bmp", 1)
            Case 4
                ConsoleWrite("Purple" & @CRLF)
                ;GUICtrlSetImage($4, "Imgs\Purple.bmp", 1)
                ;Sleep($TestSleep)
                ;GUICtrlSetImage($4, "Imgs\FadedPurple.bmp", 1)
        EndSwitch
    Next

    ConsoleWrite(@CRLF) ; Just for testing

    ; Set the flag to show we are waiting for user input
    $CheckingAnswer = 1

EndFunc   ;==>EasyGame

Func CheckAnswer()

    $CheckingAnswer = 0
    ; Compare the colours in $UserAnswer to those in the display list
    For $i = 1 To $CurrentLevel
        ; If the colours do not match
        If StringMid($sUserAnswer, $i, 1) <> StringMid($Var, $i, 1) Then
            MsgBox(0, "Oops", "You did not pick correctly")
            ; Rese the answer string
            $sUserAnswer = ""
            ; Return
            Return
        EndIf
    Next
    ; But if they do
    MsgBox(0, "Good", "You picked correctly")

    ; Reset the answer string
    $sUserAnswer = ""

    ; And increase level for next run
    $CurrentLevel += 1
    If $CheckingAnswer = 21 Then
        MsgBox(0, "Congrats", "You have completed the Easy level")
        ; Reset the level
        $CurrentLevel = 1
    EndIf

EndFunc

Func Blue()

    ; return if we are not ready
    If Not $CheckingAnswer Then Return

    ; Add the colour value to the list
    $sUserAnswer &= "1"

    ; Check if we have enough values in the list to start the check
    If StringLen($sUserAnswer) = $CurrentLevel Then
        CheckAnswer()
    EndIf

EndFunc

Func Green()

    If Not $CheckingAnswer Then Return
    $sUserAnswer &= "2"
    If StringLen($sUserAnswer) = $CurrentLevel Then
        CheckAnswer()
    EndIf

EndFunc

Func Red()

    If Not $CheckingAnswer Then Return
    $sUserAnswer &= "3"
    If StringLen($sUserAnswer) = $CurrentLevel Then
        CheckAnswer()
    EndIf

EndFunc

Func Purple()

    If Not $CheckingAnswer Then Return
    $sUserAnswer &= "4"
    If StringLen($sUserAnswer) = $CurrentLevel Then
        CheckAnswer()
    EndIf

EndFunc

Func CloseGUI()
    Exit
EndFunc

Please ask if you do not understand what I have done or why I have done it - the idea is for you to learn! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Wow! A complete re-code with commenting. Damein, consider yourself very lucky!


[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]

Share this post


Link to post
Share on other sites

That worked amazingly Melba, thanks a lot!

I got it to work at home, but it was no where near as clean as this :)


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

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