Sign in to follow this  
Followers 0
litlmike

Optimizing/Condensing Commands

11 posts in this topic

I am trying to figure out how to accomplish this without creating 55 different cases for every scenario, instead maybe like 3-5 cases. The first 3 buttons work, and so does the one titled "Silver". Functionally this will show exactly what I want to do with the script, but I don't know how to take this to the next step.

I was thinking that an array or loop should be able to accomplish this, but I really can't figure out how. Can anyone tell me HOW I can arrive at this answer?

Thanks in Advance.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Program Files\Microsoft Office\z\New\GEM TD\GemTd.kxf
$Form1 = GUICreate("Gem TD", 990, 813, 0, 0)
$Group1 = GUICtrlCreateGroup("", 10, 10, 153, 297)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button1 = GUICtrlCreateButton("Sapphire", 25, 59, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Diamond", 25, 89, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Opal", 25, 119, 75, 25, 0)
$Button4 = GUICtrlCreateButton("Emerald", 25, 149, 75, 25, 0)
$Button5 = GUICtrlCreateButton("Aquamarine", 25, 179, 75, 25, 0)
$Button6 = GUICtrlCreateButton("Ruby", 25, 209, 75, 25, 0)
$Button7 = GUICtrlCreateButton("Topaz", 25, 239, 75, 25, 0)
$Button8 = GUICtrlCreateButton("Amethyst", 25, 269, 75, 25, 0)
$Input1 = GUICtrlCreateInput("0", 110, 59, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input2 = GUICtrlCreateInput("0", 110, 89, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input3 = GUICtrlCreateInput("0", 110, 119, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input4 = GUICtrlCreateInput("0", 110, 149, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input5 = GUICtrlCreateInput("0", 110, 179, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input6 = GUICtrlCreateInput("0", 110, 209, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input7 = GUICtrlCreateInput("0", 110, 239, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input8 = GUICtrlCreateInput("0", 110, 269, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Label1 = GUICtrlCreateLabel("Chipped", 55, 26, 76, 26)
GUICtrlSetFont(-1, 14, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 170, 10, 153, 297)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button9 = GUICtrlCreateButton("Sapphire", 185, 59, 75, 25, 0)
$Button10 = GUICtrlCreateButton("Diamond", 185, 89, 75, 25, 0)
$Button11 = GUICtrlCreateButton("Opal", 185, 119, 75, 25, 0)
$Button12 = GUICtrlCreateButton("Emerald", 185, 149, 75, 25, 0)
$Button13 = GUICtrlCreateButton("Aquamarine", 185, 179, 75, 25, 0)
$Button14 = GUICtrlCreateButton("Ruby", 185, 209, 75, 25, 0)
$Button15 = GUICtrlCreateButton("Topaz", 185, 239, 75, 25, 0)
$Button16 = GUICtrlCreateButton("Amethyst", 185, 269, 75, 25, 0)
$Input9 = GUICtrlCreateInput("0", 270, 59, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input10 = GUICtrlCreateInput("0", 270, 89, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input11 = GUICtrlCreateInput("0", 270, 119, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input12 = GUICtrlCreateInput("0", 270, 149, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input13 = GUICtrlCreateInput("0", 270, 179, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input14 = GUICtrlCreateInput("0", 270, 209, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input15 = GUICtrlCreateInput("0", 270, 239, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input16 = GUICtrlCreateInput("0", 270, 269, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Flawed", 215, 26, 65, 26)
GUICtrlSetFont(-1, 14, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 330, 10, 153, 297)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button17 = GUICtrlCreateButton("Sapphire", 345, 59, 75, 25, 0)
$Button18 = GUICtrlCreateButton("Diamond", 345, 89, 75, 25, 0)
$Button19 = GUICtrlCreateButton("Opal", 345, 119, 75, 25, 0)
$Button20 = GUICtrlCreateButton("Emerald", 345, 149, 75, 25, 0)
$Button21 = GUICtrlCreateButton("Aquamarine", 345, 179, 75, 25, 0)
$Button22 = GUICtrlCreateButton("Ruby", 345, 209, 75, 25, 0)
$Button23 = GUICtrlCreateButton("Topaz", 345, 239, 75, 25, 0)
$Button24 = GUICtrlCreateButton("Amethyst", 345, 269, 75, 25, 0)
$Input17 = GUICtrlCreateInput("0", 430, 59, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input18 = GUICtrlCreateInput("0", 430, 89, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input19 = GUICtrlCreateInput("0", 430, 119, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input20 = GUICtrlCreateInput("0", 430, 149, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input21 = GUICtrlCreateInput("0", 430, 179, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input22 = GUICtrlCreateInput("0", 430, 209, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input23 = GUICtrlCreateInput("0", 430, 239, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input24 = GUICtrlCreateInput("0", 430, 269, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Label3 = GUICtrlCreateLabel("Normal", 375, 26, 64, 26)
GUICtrlSetFont(-1, 14, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("", 490, 10, 153, 297)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button25 = GUICtrlCreateButton("Sapphire", 505, 59, 75, 25, 0)
$Button26 = GUICtrlCreateButton("Diamond", 505, 89, 75, 25, 0)
$Button27 = GUICtrlCreateButton("Opal", 505, 119, 75, 25, 0)
$Button28 = GUICtrlCreateButton("Emerald", 505, 149, 75, 25, 0)
$Button29 = GUICtrlCreateButton("Aquamarine", 505, 179, 75, 25, 0)
$Button30 = GUICtrlCreateButton("Ruby", 505, 209, 75, 25, 0)
$Button31 = GUICtrlCreateButton("Topaz", 505, 239, 75, 25, 0)
$Button32 = GUICtrlCreateButton("Amethyst", 505, 269, 75, 25, 0)
$Input25 = GUICtrlCreateInput("0", 590, 59, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input26 = GUICtrlCreateInput("0", 590, 89, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input27 = GUICtrlCreateInput("0", 590, 119, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input28 = GUICtrlCreateInput("0", 590, 149, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input29 = GUICtrlCreateInput("0", 590, 179, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input30 = GUICtrlCreateInput("0", 590, 209, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input31 = GUICtrlCreateInput("0", 590, 239, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input32 = GUICtrlCreateInput("0", 590, 269, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Label4 = GUICtrlCreateLabel("Flawless", 535, 26, 78, 26)
GUICtrlSetFont(-1, 14, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("", 650, 10, 153, 297)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button33 = GUICtrlCreateButton("Sapphire", 665, 59, 75, 25, 0)
$Button34 = GUICtrlCreateButton("Diamond", 665, 89, 75, 25, 0)
$Button35 = GUICtrlCreateButton("Opal", 665, 119, 75, 25, 0)
$Button36 = GUICtrlCreateButton("Emerald", 665, 149, 75, 25, 0)
$Button37 = GUICtrlCreateButton("Aquamarine", 665, 179, 75, 25, 0)
$Button38 = GUICtrlCreateButton("Ruby", 665, 209, 75, 25, 0)
$Button39 = GUICtrlCreateButton("Topaz", 665, 239, 75, 25, 0)
$Button40 = GUICtrlCreateButton("Amethyst", 665, 269, 75, 25, 0)
$Input33 = GUICtrlCreateInput("0", 750, 59, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input34 = GUICtrlCreateInput("0", 750, 89, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input35 = GUICtrlCreateInput("0", 750, 119, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input36 = GUICtrlCreateInput("0", 750, 149, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input37 = GUICtrlCreateInput("0", 750, 179, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input38 = GUICtrlCreateInput("0", 750, 209, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input39 = GUICtrlCreateInput("0", 750, 239, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Input40 = GUICtrlCreateInput("0", 750, 269, 35, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$Label5 = GUICtrlCreateLabel("Perfect", 695, 26, 66, 26)
GUICtrlSetFont(-1, 14, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group6 = GUICtrlCreateGroup("", 10, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button41 = GUICtrlCreateButton("Silver", 32, 336, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label6 = GUICtrlCreateLabel("C. Diamond", 32, 370, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label7 = GUICtrlCreateLabel("C. Topaz", 32, 390, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label8 = GUICtrlCreateLabel("C. Sapphire", 32, 410, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group7 = GUICtrlCreateGroup("", 138, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button42 = GUICtrlCreateButton("Malachite", 160, 336, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label9 = GUICtrlCreateLabel("C. Opal", 160, 370, 48, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label10 = GUICtrlCreateLabel("C. Ruby", 160, 390, 51, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label11 = GUICtrlCreateLabel("C. Aquamarine", 160, 410, 90, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group8 = GUICtrlCreateGroup("", 266, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button43 = GUICtrlCreateButton("Star Ruby", 288, 336, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label12 = GUICtrlCreateLabel("C. Amethyst", 288, 370, 77, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label13 = GUICtrlCreateLabel("C. Ruby", 288, 390, 51, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label14 = GUICtrlCreateLabel("Flawed Ruby", 288, 410, 79, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group9 = GUICtrlCreateGroup("", 394, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button44 = GUICtrlCreateButton("Jade", 408, 336, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label15 = GUICtrlCreateLabel("Emerald", 409, 370, 52, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label16 = GUICtrlCreateLabel("Opal", 409, 390, 31, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label17 = GUICtrlCreateLabel("Flawed Sapphire", 409, 410, 100, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group10 = GUICtrlCreateGroup("", 522, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button45 = GUICtrlCreateButton("Red Crystal", 536, 336, 91, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label18 = GUICtrlCreateLabel("Flawless Emerald", 532, 370, 107, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label19 = GUICtrlCreateLabel("Ruby", 532, 390, 34, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label20 = GUICtrlCreateLabel("Flawed Amethyst", 532, 410, 105, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group11 = GUICtrlCreateGroup("", 650, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button46 = GUICtrlCreateButton("Dark Emerald", 664, 336, 91, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label21 = GUICtrlCreateLabel("P. Emerald", 655, 370, 69, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label22 = GUICtrlCreateLabel("Flawless Sapphire", 655, 390, 110, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label23 = GUICtrlCreateLabel("Flawed Topaz", 655, 410, 84, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group12 = GUICtrlCreateGroup("", 778, 320, 121, 121)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button47 = GUICtrlCreateButton("Yellow Sapphire", 785, 336, 109, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label24 = GUICtrlCreateLabel("P. Sapphire", 800, 370, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label25 = GUICtrlCreateLabel("Flawed Topaz", 800, 390, 84, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label26 = GUICtrlCreateLabel("Flawless Ruby", 800, 410, 89, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group13 = GUICtrlCreateGroup("", 10, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button48 = GUICtrlCreateButton("Blood Stone", 32, 461, 83, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label27 = GUICtrlCreateLabel("P. Ruby", 17, 495, 51, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label28 = GUICtrlCreateLabel("Flawl. Aquamarine", 17, 515, 111, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label29 = GUICtrlCreateLabel("Amethyst", 17, 535, 60, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group14 = GUICtrlCreateGroup("", 138, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button49 = GUICtrlCreateButton("Uranium 238", 152, 461, 99, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label30 = GUICtrlCreateLabel("P. Topaz", 160, 495, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label31 = GUICtrlCreateLabel("Flawed Topaz", 160, 515, 84, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label32 = GUICtrlCreateLabel("Sapphire", 160, 535, 55, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group15 = GUICtrlCreateGroup("", 266, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button50 = GUICtrlCreateButton("Gold", 288, 461, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label33 = GUICtrlCreateLabel("P. Amethyst", 276, 495, 77, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label34 = GUICtrlCreateLabel("Flawl. Amethyst", 276, 515, 98, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label35 = GUICtrlCreateLabel("Flawed Diamond", 276, 535, 100, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group16 = GUICtrlCreateGroup("", 394, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button51 = GUICtrlCreateButton("Pink Diamond", 400, 461, 107, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label36 = GUICtrlCreateLabel("P. Topaz", 424, 495, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label37 = GUICtrlCreateLabel("Topaz", 424, 515, 39, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label38 = GUICtrlCreateLabel("Diamond", 424, 535, 55, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group17 = GUICtrlCreateGroup("", 522, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button52 = GUICtrlCreateButton("Black Opal", 544, 461, 75, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "arial")
$Label39 = GUICtrlCreateLabel("P. Opal", 544, 495, 48, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label40 = GUICtrlCreateLabel("Flawl. Diamond", 544, 515, 93, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label41 = GUICtrlCreateLabel("Aquamarine", 544, 535, 73, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group18 = GUICtrlCreateGroup("", 650, 445, 121, 137)
GUICtrlSetFont(-1, 8, 400, 0, "arial")
$Button53 = GUICtrlCreateButton("Paraiba Tourmaline", 654, 461, 114, 25, 0)
GUICtrlSetFont(-1, 8, 800, 0, "arial")
$Label42 = GUICtrlCreateLabel("P. Aquamarine", 660, 495, 90, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label43 = GUICtrlCreateLabel("Flawless Opal", 660, 515, 86, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label44 = GUICtrlCreateLabel("Flawed Emerald", 660, 535, 97, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
$Label45 = GUICtrlCreateLabel("Flawed Aquam.", 660, 555, 94, 20)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Button1
        GUICtrlSetColor ( $Label8, 0x3cb371)
        _AddOne ($Input1)
    Case $Button2
        GUICtrlSetColor ( $Label6, 0x3cb371)
        _AddOne ($Input2)
    Case $Button3
        GUICtrlSetColor ( $Label7, 0x3cb371)
        _AddOne ($Input3)
    Case $Button41
        _MinusOne ($Input1, $Label8)
        _MinusOne ($Input2, $Label6)
        _MinusOne ($Input3, $Label7)
EndSwitch
WEnd

Func _AddOne ($Input)
    $Number = GuiCtrlRead ($Input)
    $Number +=1
    GUICtrlSetData ($Input, $Number)
    
EndFunc

Func _MinusOne ($Input, $Label)
    $Number = GuiCtrlRead ($Input)
    $Number -=1
    GUICtrlSetData ($Input, $Number)
    
    If GuiCtrlRead ($Input) < 1 Then GUICtrlSetColor ( $Label, 0x000000)

EndFunc

Share this post


Link to post
Share on other sites



I am trying to figure out how to accomplish this without creating 55 different cases for every scenario, instead maybe like 3-5 cases. The first 3 buttons work, and so does the one titled "Silver". Functionally this will show exactly what I want to do with the script, but I don't know how to take this to the next step.

I was thinking that an array or loop should be able to accomplish this, but I really can't figure out how. Can anyone tell me HOW I can arrive at this answer?

Thanks in Advance.

Use event mode. Save the button and input control IDs to a 2D array $avButtons:

[0][0] = Count

[1][0] = first button control ID

[1][1] = first button's input control ID

[2][0] = second button control ID

[2][1] = second button's input control ID

...

[n][0] = last button control ID

[n][1] = last button's input control ID

Point them all to the same button function on event...

Global $avButtons[54][2]
$avButtons[0][0] = UBound($avButtons) - 1

For $n = 0 To $avButtons[0][0]
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Sapphire", $x_button, $y_button, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
NextoÝ÷ ٩ݺǭæî¶Ú'ßÛPD²¶h¢H­º§¶®¶²jw©àzØ^jk¢âj×¢­jëh×6Func _ButtonHit()
    Local $i, $ID_button = @GUI_CtrlId
    For $i = 1 To $avButtons[0][0]
        If $avButtons[$i][0] = $ID_button Then
            GUICtrlSetData($avButtons[$i][1], Number(GUICtrlRead($avButtons[$i][1])) + 1)
            ExitLoop
        EndIf
    Next
EndFunc

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Use event mode. Save the button and input control IDs to a 2D array $avButtons:

Excellent, I will go give this a try. Here is another question, is there a way to declare the button & input controls "automatically", like with a loop or something? Or, do I just have to declare them all individually?

Share this post


Link to post
Share on other sites

Excellent, I will go give this a try. Here is another question, is there a way to declare the button & input controls "automatically", like with a loop or something? Or, do I just have to declare them all individually?

That's exactly what the first For/Next loop I posted above is doing. You have to add the logic to calculate the x/y positions for the controls. It'll be fun!

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

That's exactly what the first For/Next loop I posted above is doing. You have to add the logic to calculate the x/y positions for the controls. It'll be fun!

:rolleyes:

Ah ha! Gotcha! Sorry I didn't understand that part the first time, I'll get working on it now. Thanks! (first time using OnEvent mode and loops to create GUIs) Edited by litlmike

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@PsaltyDS

Can you tell me if I am on the correct path? I feel like this is wrong... and not what you had in mind originally. I didn't know how to resolve creating buttons with different text, and uniquely declaring the variable.

#include <GUIConstants.au3>

$Form1 = GUICreate("Gem TD", 990, 813, 0, 0)

Global $avButtons[35][2]
$avButtons[0][0] = UBound($avButtons) - 1
$x_button = 15
$y_button = 15
$x_input = 100
$y_input = 15

For $n = 0 To 4
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Sapphire", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 4 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next



For $n = 4 To 8
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Diamond", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 8 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
    
Next

For $n = 8 To 12
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Opal", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 12 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next

For $n = 12 To 16
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Emerald", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 16 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next

For $n = 16 To 20
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Aquamarine", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 20 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next

For $n = 20 To 24
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Ruby", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 24 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next

For $n = 24 To 28
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Topaz", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 28 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
    
Next

For $n = 28 To 32
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons[$n][0] = GUICtrlCreateButton("Amethyst", $x_button, $y_button, 75, 25, 0)
        
;~     GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    $x_button += 135
    $x_input += 135
    
    If $n = 32 Then
        $x_button = 15
        $y_button += 30
        $x_input = 100
        $y_input += 30
    EndIf
Next

GUISetState(@SW_SHOW)

While 1
    Sleep (1000)
WEnd
Edited by litlmike

Share this post


Link to post
Share on other sites

I don't have time to write any code right now, but the secret is in the arrays you use. Make an array of button names and cycle through them (there were like 6 names that repeated), then increment your column (x position) and start over on the same button text.

I'll look closer at it later.

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I don't have time to write any code right now, but the secret is in the arrays you use. Make an array of button names and cycle through them (there were like 6 names that repeated), then increment your column (x position) and start over on the same button text.

I'll look closer at it later.

:rolleyes:

I tried this, based on my interpretation of what you were saying.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 

$Form1 = GUICreate("Gem TD", 990, 813, 0, 0)

Global $avButtons1[5][2], $avButtons2[5][2], $avButtons3[5][2], $avButtons4[5][2], $avButtons5[5][2], $avButtons6[5][2], $avButtons7[5][2], $avButtons8[5][2]

$avButtons1[0][0] = UBound($avButtons1) - 1
$avButtons2[0][0] = UBound($avButtons2) - 1
$avButtons3[0][0] = UBound($avButtons3) - 1
$avButtons4[0][0] = UBound($avButtons4) - 1
$avButtons5[0][0] = UBound($avButtons5) - 1
$avButtons6[0][0] = UBound($avButtons6) - 1
$avButtons7[0][0] = UBound($avButtons7) - 1
$avButtons8[0][0] = UBound($avButtons8) - 1

Global $x_button = 15, $y_button = 15, $x_input = 100, $y_input = 15

For $n = 0 To 4
    ;
    ; Do some math here to calculate $x_button, $y_button, $x_input, and $y_input
    ;
    $avButtons1[$n][0] = GUICtrlCreateButton("Sapphire", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons1[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
    
    $avButtons2[$n][0] = GUICtrlCreateButton("Diamond", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons2[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
    
    $avButtons3[$n][0] = GUICtrlCreateButton("Opal", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons3[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
        
    _ButtonAlignment ()
    
    $avButtons4[$n][0] = GUICtrlCreateButton("Emerald", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons4[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
    
    $avButtons5[$n][0] = GUICtrlCreateButton("Aquamarine", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons5[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
    
    $avButtons6[$n][0] = GUICtrlCreateButton("Ruby", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons6[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))

    _ButtonAlignment ()
    
    $avButtons7[$n][0] = GUICtrlCreateButton("Topaz", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons7[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
    
    $avButtons8[$n][0] = GUICtrlCreateButton("Amethyst", $x_button, $y_button, 75, 25, 0)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avButtons8[$n][0] = GUICtrlCreateInput("0", $x_input, $y_input, 35, 22, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
    
    _ButtonAlignment ()
        
    $y_button = 15
    $y_input = 15
    
    $x_button += 135
    $x_input += 135
Next


GUISetState(@SW_SHOW)

While 1
    Sleep (1000)
WEnd

Func _ButtonHit()
    Local $i, $ID_button = @GUI_CtrlId
    For $i = 1 To $avButtons1[0][0]
        If $avButtons1[$i][0] = $ID_button Then
            GUICtrlSetData($avButtons1[$i][1], Number(GUICtrlRead($avButtons1[$i][1])) + 1)
            ExitLoop
        EndIf
    Next
EndFunc

Func _ButtonAlignment ()
    $y_button += 30
    $y_input += 30
EndFunc

Share this post


Link to post
Share on other sites

I tried this, based on my interpretation of what you were saying.

The 2D array was a little more unweildy than expected for this. I tried it this way:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

; ================================================
;  Edit these strings to add/remove categories
; ================================================
Global $sConditions = "Chipped, Flawed, Normal, Flawless, Perfect"
Global $sStones = "Saphire, Diamond, Opal, Emerald, Aquamarine, Ruby, Topaz, Amethyst"

; Create arrays
Global $avConditions = StringSplit($sConditions, ",")
Global $avStones = StringSplit($sStones, ",")
$n = $avConditions[0] * $avStones[0]
Global $avButtons[$n + 1]
$avButtons[0] = $n
Global $avInputs[$n + 1]
$avInputs[0] = $n

; Create dimensions for GUI
Global $Label_H = 25
Global $Button_W = 75, $Button_H = 25
Global $Input_W = 35, $Input_H = 25
Global $Group_W = ($Button_W + $Input_W + 30), $Group_H = ($Label_H + 20 + (($Button_H + 10) * $avStones[0]))
Global $Label_W = $Group_W - 20
Global $GUI_W = (($avConditions[0] * ($Group_W + 10)) + 10), $GUI_H = $Group_H + 20

; Create coordinates for controls
Global $Label_X = 20, $Label_Y = 20
Global $Button_X_Start = 20, $Button_Y_Start = $Label_H + 30
Global $Input_X_Start = $Button_W + 30, $Input_Y_Start = $Label_H + 30

; Create GUI
$Form1 = GUICreate("Gem TD", $GUI_W, $GUI_H)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

; Add groups for each condition
$iButton = 1
For $iCondition = 1 To $avConditions[0]
    ; Calculate group positions
    $Group_X = 10 + (($Group_W + 10) * ($iCondition - 1))
    $Group_Y = 10
    $Button_X = $Button_X_Start + (($Group_W + 10) * ($iCondition - 1))
    $Input_X = $Input_X_Start + (($Group_W + 10) * ($iCondition - 1))
    
    ; Create group
    GUICtrlCreateGroup("", $Group_X, $Group_Y, $Group_W, $Group_H)
    GUICtrlSetFont(-1, 8, 400, 0, "arial")
    GUICtrlCreateLabel($avConditions[$iCondition], $Group_X + 10, $Group_Y + 10, $Label_W, $Label_H, $SS_Center)
    GUICtrlSetFont(-1, 14, 400, 0, "arial")
    
    ; Add controls for each type of stone
    For $iStone = 1 To $avStones[0]
        ; Calculate control positions
        $Button_Y = $Button_Y_Start + (($Button_H + 10) * ($iStone - 1))
        $Input_Y = $Button_Y
        
        ; Add button and input controls
        $avButtons[$iButton] = GUICtrlCreateButton($avStones[$iStone], $Button_X, $Button_Y, $Button_W, $Button_H)
        GUICtrlSetOnEvent(-1, "_ButtonHit")
        $avInputs[$iButton] = GUICtrlCreateInput("0", $Input_X, $Input_Y, $Input_W, $Input_H, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
        
        ; Increment button count
        $iButton += 1
    Next
Next

; Show GUI
GUISetState(@SW_SHOW)
While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _ButtonHit()
    Local $i, $ID_button = @GUI_CtrlId
    For $i = 1 To $avButtons[0]
        If $avButtons[$i] = $ID_button Then
            GUICtrlSetData($avInputs[$i], Number(GUICtrlRead($avInputs[$i])) + 1)
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_ButtonHit

Creates everything for the upper half, and dynamically creates the GUI size and all control locations based on the number of conditions and stones provided at the top. You could add or remove stones or conditions just by editing those two strings, and everything else will adjust.

It's a little shorter than your last, but much cleaner and easier to tweak, and illustrates the technique much better.

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

It's a little shorter than your last, but much cleaner and easier to tweak, and illustrates the technique much better.

I can't tell you how long I been trying to understand this GUI creation technique... too long. I really appreciate the help. I been working on what you gave me for the last day and I have finally gotten a little bit further. I uglied up your script and added the next part. :rolleyes:

Now where I am stuck is that for the next region (bottom of GUI) I have to create labels for the Buttons from $sCombos (my addition). If you can answer this, that would actually answer a much larger question I have had about "pointing". In the buttons I added there are a combos of "Stones" that make up that button. For instance, "Silver" is made from "Chipped Sapphire", "Chipped Topaz" and "Chipped Diamond". Thus, I want to put 3 labels to the right of the "Silver" button with their combination makeup. I would like to do this for the 13 combinations (each combo is unique).

I guess the quesiton is what is the best way to do this. Do I have to recreate 13 different loops/arrays for this, or can I "assign" these "properties" so that the every different combination shows the correct label?

Thanks!

Share this post


Link to post
Share on other sites

I can't tell you how long I been trying to understand this GUI creation technique... too long. I really appreciate the help. I been working on what you gave me for the last day and I have finally gotten a little bit further. I uglied up your script and added the next part. :rambo:

Now where I am stuck is that for the next region (bottom of GUI) I have to create labels for the Buttons from $sCombos (my addition). If you can answer this, that would actually answer a much larger question I have had about "pointing". In the buttons I added there are a combos of "Stones" that make up that button. For instance, "Silver" is made from "Chipped Sapphire", "Chipped Topaz" and "Chipped Diamond". Thus, I want to put 3 labels to the right of the "Silver" button with their combination makeup. I would like to do this for the 13 combinations (each combo is unique).

I guess the quesiton is what is the best way to do this. Do I have to recreate 13 different loops/arrays for this, or can I "assign" these "properties" so that the every different combination shows the correct label?

Thanks!

It sounds from your description like this could certainly be done with the same technique. Create an array early in the script that contains a list of buttons/labels/combos/whatever. The hard (and interesting) part is to code a loop that does the math to read each set out and place them at the proper X/Y location. No code here because I'm having a hard time envisioning what you want it to look like.

How does what you describe here compare with the lower-half stuff from your earlier GUI?

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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