Jump to content

i screwed a simple counter...


Recommended Posts

Dim $test[3]    ;I don't know how to declare all of the elements in one line
$test[0]=0
$test[1]=0
$test[2]=0
While 1=1
    $test[0]=$test[0]+1     ;The supposed "drive", for lack of better word
    If $test[0]>9 Then      ;The first step to overcome
        $test[1]=$test[1]+1 ;Slowly, but surely, you climb one big step every 10 small ones
        $test[0]=0
    ElseIf $test[1]>9 Then  ;The second step to overcome. Problem HERE.
        $test[2]=$test[2]+1 ;10 big steps = 1 humongous step
        $test[1]=0          ;Reset big steps
        $test[0]=0          ;This is for good measure i guess....
    ElseIf $test[0]=9 And $test[1]=9 And $test[2]=9 Then    ;The ender. All things have to end
        MsgBox(1,"","ended")    ;Visual notice
        Exit
    EndIf
    ConsoleWrite($test[0]&" "&$test[1]&" "&$test[2]&@CRLF)
WEnd

i'm having a small problem here. This doesn't count as high as i would like. this, of course, is a simple test. otherwise, i wouldn't add all those comments.

$test[0] doesn't seem to have any problems UNTILL THE VERY END. THEN it reaches only 8.

$test[1] for some unknown reason actually REACHES 10 (IE 0 10 0)

$test[2] doesn't seem to have any problems at all, but i'm sure it'll make something nasty as soon as i make this thing 5 elements big. My current guess it'll act like $test[1], but i don't know....

also, as i mentioned earlier, it ends at 8 9 9 instead of 9 9 9. That 1 0 0 is quite a big difference for me. a theoretical, of course, as i doubt anyone would actually CARE to reach, but i still it to work properly.

I'm trying to work out a score system, and since i can't just StringSplit() the thing (I spent a whole day dedicated to struggle with StringSplit()) i decided to count it MANUALLY.

I'm hoping to get to 5 elements, but unless i can make 3 work properly, i can't even begin thinking about adding 2 more.

help me make this count properly please.

Link to comment
Share on other sites

  • Developers

Dim $test[3]    ;I don't know how to declare all of the elements in one line
$test[0]=0
$test[1]=0
$test[2]=0
While 1=1
    $test[0]=$test[0]+1     ;The supposed "drive", for lack of better word
    If $test[0]>9 Then      ;The first step to overcome
        $test[1]=$test[1]+1 ;Slowly, but surely, you climb one big step every 10 small ones
        $test[0]=0
    EndIf
    If $test[1]>9 Then  ;The second step to overcome. Problem HERE.
        $test[2]=$test[2]+1 ;10 big steps = 1 humongous step
        $test[1]=0          ;Reset big steps
    EndIf
    If $test[0]=9 And $test[1]=9 And $test[2]=9 Then    ;The ender. All things have to end
        MsgBox(1,"","ended")    ;Visual notice
        Exit
    EndIf
    ConsoleWrite($test[0]&" "&$test[1]&" "&$test[2]&@CRLF)
WEnd

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Dim $test[3]    ;I don't know how to declare all of the elements in one line
$test[0]=0
$test[1]=0
$test[2]=0
Syntax for declaring and initializing array:
Dim $test[3] = [0, 0, 0]

Same syntax for a 2D array:

Dim $test[3][2] = [[0,1], [0,1], [0, 1]]

:D

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

  • Developers

@Jos: Yeah... if that would have worked that way, i wouldn't post this here.

the output in the console is like this

9 9 <infinity>

What do you mean?

Works fine for me as far as I can tell.

EDIT: Ok one minor change to display also the last value:

Dim $test[3]    ;I don't know how to declare all of the elements in one line
$test[0]=0
$test[1]=0
$test[2]=0
While 1=1
    $test[0]=$test[0]+1     ;The supposed "drive", for lack of better word
    If $test[0]>9 Then      ;The first step to overcome
        $test[1]=$test[1]+1 ;Slowly, but surely, you climb one big step every 10 small ones
        $test[0]=0
    EndIf
    If $test[1]>9 Then  ;The second step to overcome. Problem HERE.
        $test[2]=$test[2]+1 ;10 big steps = 1 humongous step
        $test[1]=0          ;Reset big steps
    EndIf
    ConsoleWrite($test[0]&" "&$test[1]&" "&$test[2]&@CRLF)
    If $test[0]=9 And $test[1]=9 And $test[2]=9 Then    ;The ender. All things have to end
        MsgBox(1,"","ended")    ;Visual notice
        Exit
    EndIf
WEnd
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

@Jos: what... the hell... did you do?! i mean, other then changing the operators to ='s.

earlier, i ment that it gets to 9 9 9 and just keeps counting on the last one. gets to like 9 9 16xx before i manage to turn it off

Take the time to look at it and understand ... you will figure it out.

You will have to learn sometime to debug this stuff yourself as this is not kindergarten.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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