Sign in to follow this  
Followers 0
cation

Finding highest value

11 posts in this topic

#1 ·  Posted (edited)

Hi guys, i wonder can you tell my how to find highest value from $button1 - $button16 and then tell that to msgbox when pressing $button20, like "nextmap will be quarry with 4(number how many times have pressed $button1) votes" with $var1, if highest value is $var2(number how many times have pressed $button2) then it could say "nextmap will be skidrow with 5 votes". I would be so grateful if someone can tell that code how i could get that what im looking for.

Heres my code

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include
#include
#include
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Map Vote", 301, 126, 369, 244)
$Button1 = GUICtrlCreateButton("Quarry", 0, 0, 75, 25)
$Button2 = GUICtrlCreateButton("Skidrow", 75, 0, 75, 25)
$Button3 = GUICtrlCreateButton("Favela", 150, 0, 75, 25)
$Button4 = GUICtrlCreateButton("Highrise", 225, 0, 75, 25)
$Button5 = GUICtrlCreateButton("Rust", 0, 25, 75, 25)
$Button6 = GUICtrlCreateButton("Afghan", 75, 25, 75, 25)
$Button7 = GUICtrlCreateButton("Wasteland", 150, 25, 75, 25)
$Button8 = GUICtrlCreateButton("Derail", 225, 25, 75, 25)
$Button9 = GUICtrlCreateButton("Estate", 0, 75, 75, 25)
$Button10 = GUICtrlCreateButton("Invasion", 75, 50, 75, 25)
$Button11 = GUICtrlCreateButton("Karachi", 150, 75, 75, 25)
$Button12 = GUICtrlCreateButton("Subbase", 225, 50, 75, 25)
$Button13 = GUICtrlCreateButton("Rundown", 0, 50, 75, 25)
$Button14 = GUICtrlCreateButton("Terminal", 75, 75, 75, 25)
$Button15 = GUICtrlCreateButton("Scrapyard", 150, 50, 75, 25)
$Button16 = GUICtrlCreateButton("Underpass", 225, 75, 75, 25)
$Button17 = GUICtrlCreateButton("Scores", 0, 100, 75, 25)
$Button18 = GUICtrlCreateButton("Close", 225, 100, 75, 25)
$Button19 = GUICtrlCreateButton("Reset", 150, 100, 75, 25)
$Button20 = GUICtrlCreateButton("Next map", 75, 100, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$var1 = 0
$var2 = 0
$var3 = 0
$var4 = 0
$var5 = 0
$var6 = 0
$var7 = 0
$var8 = 0
$var9 = 0
$var10 = 0
$var11 = 0
$var12 = 0
$var13 = 0
$var14 = 0
$var15 = 0
$var16 = 0


While 1
$msg = GUIGetMsg()
Select

Case $msg = $Button1
$var1 = $var1 + 1

Case $msg = $Button2
$var2 = $var2 + 1

Case $msg = $Button3
$var3 = $var3 + 1

Case $msg = $Button4
$var4 = $var4 + 1

Case $msg = $Button5
$var5 = $var5 + 1

Case $msg = $Button6
$var6 = $var6 + 1

Case $msg = $Button7
$var7 = $var7 + 1

Case $msg = $Button8
$var8 = $var8 + 1

Case $msg = $Button9
$var9 = $var9 + 1

Case $msg = $Button10
$var10 = $var10 + 1

Case $msg = $Button11
$var11 = $var11 + 1

Case $msg = $Button12
$var12 = $var12 + 1

Case $msg = $Button13
$var13 = $var13 + 1

Case $msg = $Button14
$var14 = $var14 + 1

Case $msg = $Button15
$var15 = $var15 + 1

Case $msg = $Button16
$var16 = $var16 + 1

Case $msg = $Button17
MsgBox(0,"Vote Scores","Quarry: " &$var1 & @CRLF & "Skidrow: " &$var2 & @CRLF & "Favela: " &$var3 & @CRLF & "Highrise: " &$var4 & @CRLF & "Rust: " &$var5 & @CRLF & "Afghan: " &$var6 & @CRLF & "Wasteland: " &$var7 & @CRLF & "Derail: " &$var8 & @CRLF & "Estate: " &$var9 & @CRLF & "Invasion: " &$var10 & @CRLF & "Karachi: " &$var11 & @CRLF & "Subbase: " &$var12 & @CRLF & "Rundown: " &$var13 & @CRLF & "Terminal: " &$var14 & @CRLF & "Scrapyard: " &$var15 & @CRLF & "Underpass: " &$var16)

Case $msg = $Button18
Exit

Case $msg = $Button19
$var1 = $var1 - $var1
$var2 = $var2 - $var2
$var3 = $var3 - $var3
$var4 = $var4 - $var4
$var5 = $var5 - $var5
$var6 = $var6 - $var6
$var7 = $var7 - $var7
$var8 = $var8 - $var8
$var9 = $var9 - $var9
$var10 = $var10 - $var10
$var11 = $var11 - $var11
$var12 = $var12 - $var12
$var13 = $var13 - $var13
$var14 = $var14 - $var14
$var15 = $var15 - $var15
$var16 = $var16 - $var16

Case $msg = $button20
if $var1 > $var2 > $var3 Then
MsgBox(0,"Nextmap", "Nextmap will be Quarry with " &$var1)
endif
;tested but failed
if $var2 > $var1 > $var3 Then
msgbox(0,"Nextmap", "Nextmap will be Skidrow with "&$var2)
endif
;tested but failed
if $var3 > $var1 > $var2 Then
msgbox(0,"Nextmap", "Nextmap will be Favela with "&$var3)
endif
;tested but failed
EndSelect
WEnd

and sorry if there is already thread about code what im looking for

Edited by cation

Share this post


Link to post
Share on other sites



cation,

Welcome to the AutoIt forum. :)

Those map names are found in Call of Duty: Modern Warfare 2. What exactly are you doing with them - and have you read the Forum Rules regarding game automation? :huh:

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

its not automation :) theres GUI where is 20 buttons and its for map vote. its totally manual and it wont do anything to games. feel free to try it

Share this post


Link to post
Share on other sites

cation,

its not automation

Delighted to hear it. :)

To solve your problem, I suggest you put the counts of the button presses into an array - then you can easily use _ArrayMaxIndex to find the element with the highest value. ;)

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)

problem is that im not very good with those arrays, so i hope you can help me somehow :) or show some example, im still newbie with coding but i know some basic stuff

Edited by cation

Share this post


Link to post
Share on other sites

cation,

Take a look at this - you can see that using arrays allows you to make the script a lot shorter: ;)

#include <GUIConstantsEx.au3>
#include <Array.au3>

; Declare arrays to hold variables and strings
Global $aTitle[21] = [21, "Quarry", "Skidrow", "Favela", "Highrise", "Rust", "Afghan", "Wasteland", "Derail", "Estate", "Invasion", _
                    "Karachi", "Subbase", "Rundown", "Terminal", "Scrapyard", "Underpass", "Scores", "Close", "Reset", "Next Map"]
Global $aButton[21]
Global $aCount[17] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

; Create the GUI
$Form1_1 = GUICreate("Map Vote", 301, 126, 369, 244)

; Create the buttons
For $i = 0 To 4
    For $j = 0 To 3
        $iTotal = ($i * 4) + $j + 1
        $iX = $j * 75
        $iY = $i * 25
        $aButton[$iTotal] = GUICtrlCreateButton($aTitle[$iTotal], $iX, $iY, 75, 25)
    Next
Next

GUISetState(@SW_SHOW)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        ; It was a count button
        Case $aButton[1] To $aButton[16]
            ; Which button was it?
            $iButton = $iMsg - $aButton[1] + 1
            ; Add to the count
            $aCount[$iButton] += 1
        Case $aButton[17]
            ; Create the listing
            $sText = ""
            For $i = 1 To 16
                $sText &= $aTitle[$i] & @TAB & @TAB & $aCount[$i] & @CRLF
            Next
            ; And display it
            MsgBox(0, "Vote Scores", $sText)
        Case $aButton[18], $GUI_EVENT_CLOSE ; Look for the [X] as well ;)
            Exit
        Case $aButton[19]
            ; Reset the array
            Global $aCount[17]  = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        Case $aButton[20]
            ; Where is the highest count?
            $iIndex = _ArrayMaxIndex($aCount, 1)
            ; And display it
            MsgBox(0, "Nextmap", "Nextmap will be " & $aTitle[$iIndex] & " with " & $aCount[$iIndex])
    EndSwitch
WEnd

Please ask if you have any questions. :)

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

i have another question and thats why i cant add any buttons to that code or dont i know how to do it.

heres my code

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include 
#include 

; Declare arrays to hold variables and strings
Global $aTitle[24] = [24, "Quarry", "Skidrow", "Favela", "Highrise", "Rust", "Afghan", "Wasteland", "Derail", "Estate", "Invasion", _
"Karachi", "Subbase", "Rundown", "Terminal", "Scrapyard", "Underpass", "Scores", "Nextmap", "Reset", "Close", _
"Map Wishes", "Counting"]
Global $aButton[24]
Global $aCount[17] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

; Create the GUI
$Form1 = GUICreate("Map Vote", 300, 150, 370, 245)

; Create the buttons
For $i = 0 To 4
For $j = 0 To 3
$iTotal = ($i * 4) + $j + 1
$iX = $j * 75
$iY = $i * 25
$aButton[$iTotal] = GUICtrlCreateButton($aTitle[$iTotal], $iX, $iY, 75, 25)
Next
Next

GUISetState(@SW_SHOW)

While 1
$iMsg = GUIGetMsg()
Switch $iMsg
; It was a count button
Case $aButton[1] To $aButton[16]
; Which button was it?
$iButton = $iMsg - $aButton[1] + 1
; Add to the count
$aCount[$iButton] += 1
Case $aButton[17]
; Create the listing
$sText = ""
For $i = 1 To 16
$sText &= $aTitle[$i] & @TAB & @TAB & $aCount[$i] & @CRLF
Next
; And display it
MsgBox(0, "Vote Scores", $sText)
Case $aButton[20], $GUI_EVENT_CLOSE ; Look for the [X] as well ;)
Exit
Case $aButton[19]
; Reset the array
Global $aCount[17] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Case $aButton[18]
; Where is the highest count?
$iIndex = _ArrayMaxIndex($aCount, 1)
; And display it
MsgBox(0, "Nextmap", "Nextmap will be " & $aTitle[$iIndex] & " with " & $aCount[$iIndex] & " vote(s)")
sleep(1000)
send("t")
sleep(100)
send("Nextmap will be " & $aTitle[$iIndex] & " with " & $aCount[$iIndex] & " vote(s)")
sleep(100)
send("{enter}")
Case $aButton[21]
send("if you have any map wishes, say it after i say so!")
send("{enter}")
Case $aButton[22]
send("i will start COUNTING now, SAY ONLY ONCE YOUR MAP!")
send("{enter}")
EndSwitch
WEnd

i hope you can solve my problem and thanks M23 about that code but i wonder is there any tutorial/guide about those $i, $j, $X and $Y and other those $ things.

thanks already :)

Share this post


Link to post
Share on other sites

i hope you can solve my problem and thanks M23 about that code but i wonder is there any tutorial/guide about those $i, $j, $X and $Y and other those $ things.

Hi, Cation. The forum comes with a great search feature; it is always a good idea to utilize this feature first. Search for Tutorials, and you will find a number of responses to your question.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

cation,

As you can see the button creation section uses 2 loops to create the buttons. If you go through the loops manually you will see that as the 2 loops run (and set varying values to $i and $j) the button array element index ($iTotal) and position coordinates ($iX and $iY) are calulated automatically. This is known as an algorithm: :)

Outer loop    Inner loop     $iTotal = ($i * 4) + $j + 1        $iX = $j * 75          $iY = $i * 25
$i = 0        $j = 0                   (0  * 4) + 0  + 1 = 1          0 *  75 = 0            0  * 25 = 0
              $j = 1                   (0  * 4) + 1  + 1 = 2          1 *  75 = 75           0  * 25 = 0
              $j = 1                   (0  * 4) + 2  + 1 = 3          2 *  75 = 150          0  * 25 = 0
              $j = 1                   (0  * 4) + 3  + 1 = 4          3 *  75 = 225          0  * 25 = 0
$i = 1        $j = 0                   (1  * 4) + 0  + 1 = 5          0 *  75 = 0            1  * 25 = 25
              $j = 1                   (1  * 4) + 1  + 1 = 6          1 *  75 = 75           1  * 25 = 25
              $j = 1                   (1  * 4) + 2  + 1 = 7          2 *  75 = 150          1  * 25 = 25
              $j = 1                   (1  * 4) + 3  + 1 = 8          3 *  75 = 225          1  * 25 = 25
$i = 2        $j = 0                   (2  * 4) + 0  + 1 = 9          0 *  75 = 0            2  * 25 = 50
              $j = 1                   (2  * 4) + 1  + 1 = 10         1 *  75 = 75           2  * 25 = 50
              $j = 1                   (2  * 4) + 2  + 1 = 11         2 *  75 = 150          2  * 25 = 50
              $j = 1                   (2  * 4) + 3  + 1 = 12         3 *  75 = 225          2  * 25 = 50
$i = 3        $j = 0                   (3  * 4) + 0  + 1 = 13         0 *  75 = 0            3  * 25 = 75
              $j = 1                   (3  * 4) + 1  + 1 = 14         1 *  75 = 75           3  * 25 = 75
              $j = 1                   (3  * 4) + 2  + 1 = 15         2 *  75 = 150          3  * 25 = 75
              $j = 1                   (3  * 4) + 3  + 1 = 16         3 *  75 = 225          3  * 25 = 75
$i = 4        $j = 0                   (4  * 4) + 0  + 1 = 17         0 *  75 = 0            4  * 25 = 100
              $j = 1                   (4  * 4) + 1  + 1 = 18         1 *  75 = 75           4  * 25 = 100
              $j = 1                   (4  * 4) + 2  + 1 = 19         2 *  75 = 150          4  * 25 = 100
              $j = 1                   (4  * 4) + 3  + 1 = 20         3 *  75 = 225          4  * 25 = 100

See how it does all the calculations for you as the loops run? ;)

If you want to add extra buttons, you do not need to use that algorithm. You can just add them manually:

#include <GUIConstantsEx.au3>
#include <Array.au3>

; Declare arrays to hold variables and strings
Global $aTitle[24] = [24, "Quarry", "Skidrow", "Favela", "Highrise", "Rust", "Afghan", "Wasteland", "Derail", "Estate", "Invasion", _
        "Karachi", "Subbase", "Rundown", "Terminal", "Scrapyard", "Underpass", "Scores", "Nextmap", "Reset", "Close", _
        "Map Wishes", "Counting"]
Global $aButton[24]
Global $aCount[17] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

; Create the GUI
$Form1 = GUICreate("Map Vote", 300, 150, 370, 245)

; Create the buttons
For $i = 0 To 4
    For $j = 0 To 3
        $iTotal = ($i * 4) + $j + 1
        $iX = $j * 75
        $iY = $i * 25
        $aButton[$iTotal] = GUICtrlCreateButton($aTitle[$iTotal], $iX, $iY, 75, 25)
    Next
Next

$aButton[21] = GUICtrlCreateButton("Get Ready", 0, 125, 150, 25)
$aButton[22] = GUICtrlCreateButton("Vote!", 150, 125, 150, 25)

GUISetState(@SW_SHOW)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        ; It was a count button
        Case $aButton[1] To $aButton[16]
            ; Which button was it?
            $iButton = $iMsg - $aButton[1] + 1
            ; Add to the count
            $aCount[$iButton] += 1
        Case $aButton[17]
            ; Create the listing
            $sText = ""
            For $i = 1 To 16
                $sText &= $aTitle[$i] & @TAB & @TAB & $aCount[$i] & @CRLF
            Next
            ; And display it
            MsgBox(0, "Vote Scores", $sText)
        Case $aButton[20], $GUI_EVENT_CLOSE ; Look for the [X] as well ;)
            Exit
        Case $aButton[19]
            ; Reset the array
            Global $aCount[17] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        Case $aButton[18]
            ; Where is the highest count?
            $iIndex = _ArrayMaxIndex($aCount, 1)
            ; And display it
            MsgBox(0, "Nextmap", "Nextmap will be " & $aTitle[$iIndex] & " with " & $aCount[$iIndex] & " vote(s)")
            Sleep(1000)
            Send("t")
            Sleep(100)
            Send("Nextmap will be " & $aTitle[$iIndex] & " with " & $aCount[$iIndex] & " vote(s)")
            Sleep(100)
            Send("{enter}")
        Case $aButton[21]
            Send("if you have any map wishes, say it after i say so!")
            Send("{enter}")
        Case $aButton[22]
            Send("i will start COUNTING now, SAY ONLY ONCE YOUR MAP!")
            Send("{enter}")
    EndSwitch
WEnd

But I do hope you are not Sending those phrases within the game itself. :huh:

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

noup :) im not and thanks a lot again M23 :) i'll try learn this coding so i dont need ask help so much :)

Share this post


Link to post
Share on other sites

cation,

Good to know. :thumbsup:

If you want to learn more about coding in Autoit then 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 the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. ;)

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

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