Sign in to follow this  
Followers 0
Kaeft

whiles and arrays counting

9 posts in this topic

Basically I'm trying to find an easy way to make a check to an array.

I'll let the code do more of the talking. You will see what I mean after you see the code.

Func votekick($name)
    $ircname = "Computer"
    $l = 0
    $looparray = UBound($votearray,2)
    while $l <= $looparray
        if $votearray[$l][0] = $name Then
            $votearray[$l][1] += 1
            $t = $looparray
            if $votearray[$l][1] >= 3 Then
                _ArrayDisplay($votearray)
                MsgBox(0,"yoik", $name & " is being a bum! going to kick when it gets implimented!")
                _IRC_SendPrivateMessage("kick " & $name,$ircname)
            EndIf
        Else
            If $t = $looparray Then
                $votearray[0][0] = $name
                $votearray[0][1] = 1
            Else
            $t += 1
            EndIf
        EndIf
    WEnd
EndFunc

Error:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

if $votearray[$l][0] = $name Then

if ^ ERROR

I want this to search through the array from $votearray[0][1] to $votearray[end of the array][1]. Which is basically just a column of names through the array. If it can't find the name then it adds it.

Share this post


Link to post
Share on other sites



Is $votearray defined as a global array? Additionally $l is not enumerated and always 0. Maybe try something like this:

Func votekick($name)
    $ircname = "Computer"
    For $i = 0 To UBound($votearray) - 1
        If $votearray[$i][0] = $name Then
            $votearray[$i][1] += 1
            If $votearray[$l][1] >= 3 Then
                _ArrayDisplay($votearray)
                MsgBox(0, "yoik", $name & " is being a bum! going to kick when it gets implimented!")
                _IRC_SendPrivateMessage("kick " & $name, $ircname)
                ExitLoop
            EndIf
        EndIf
    Next
EndFunc   ;==>votekick

Share this post


Link to post
Share on other sites

I'll let the code do more of the talking.

I think your code speaks a different dialect. I had some trouble figuring out exactly what you wanted to do and had to make some assumptions. Here is what I think it's meant to do.

I think the main problem was the one Jaberwocky pointed out, but ran into some issues where your code contradicted itsself.

#include <array.au3>
Global $votearray[4][2] = [["Paul",0],["Jim",0],["Richard",0],["Louis",0]] ;I assume $votearray would look something like this

;just made a gui to test the function with.
#region GUI
Local $aCtrlButton[UBound($votearray)]
Local $msg

GUICreate("testgui")
For $i = 0 To UBound($aCtrlButton) -1
    $aCtrlButton[$i] = GUICtrlCreateButton($votearray[$i][0],10,10+($i*25),100,20)
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case 0
            ContinueLoop
        Case -3
            Exit
    EndSwitch
    For $i = 0 To UBound($aCtrlButton) -1
        If $msg = $aCtrlButton[$i] Then
            votekick($votearray[$i][0])
            _ArrayDisplay($votearray)
            ContinueLoop 2
        EndIf
    Next
WEnd
#endregion


Func votekick($name)
    Local $ircname = "Computer"

    ;you where counting the "collumns", while the rest of the script indicates you need to count "rows"
    ;For loops are made of win when working with arrays. Keep in mind that the last index = "arraysize"-1 (if the array has 18 indices, the last one is 17)
    For $l = 0 To UBound($votearray)-1
    If $votearray[$l][0] = $name Then ;found the matching name
            If $votearray[$l][1] < 2 Then ;if that name doesn't have to many votes yet...
                $votearray[$l][1] += 1 ;increase his votes by 1
            Else
    MsgBox(0,"yoik", $name & " is being a bum! going to kick when it gets implimented!")
                _IRC_SendPrivateMessage("kick " & $name,$ircname)
                $votearray[$l][1] = 0 ;reset his votes
                ;you might prefer to _ArrayDelete() that row here (my example GUI would break)
            EndIf
            Return ;at this point there is no reason to continue the loop, unless the same name may occur twice
        EndIf
    Next
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You guys are the bomb. I don't care what the [insert higher power here] says.

The array is going to be dynamic.

Basically if the function is called with a name. It checks for the name, if the name doesn't exists then it adds it to the array. Right now the array is dimed as $votearray[1][5].

If I need to add another row would I have to redim it?

Edited by Kaeft

Share this post


Link to post
Share on other sites

The array is going to be dynamic.

I got that, but it's always going to have the name in collumn0, and the votes in collumn1 right?

If I need to add another row would I have to redim it?

Yes, unless you give the array a fixed size that is always going to be large enough to hold all entries.

ReDim $votearray[UBound($votearray)+1][UBound($votearray,2)] ;add a row
ReDim $votearray[UBound($votearray)][UBound($votearray,2)+1] ;add a collumn

P.S. As far as I know _ArrayAdd can only write to collumn0, so it's benefits are kind of lost on multi dimension arrays.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

P.S. As far as I know _ArrayAdd can only write to collumn0, so it's benefits are kind of lost on multi dimension arrays.

Yeah, I just woke up. I sometimes forget which functions have that limitation. Sorry. Edited by czardas

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