# If Random()

## Recommended Posts

Too many Else for If

```WinActivate("")
sleep(1000)
If Random() < 0.7 Then  ; Too many else, to If. How should I do this? :S
Send("{m}")
Send("{m}")
Else
Send("{l}")
Send("{l}")
Else
Send("{R}")
Send("{Enter}")
Else
Send("{Space}")
Else
Send("{I}")
Send("{I}")
Else
Send("{W}")
Else
Send("{S}")
Else
Send("{Q}")
Else
Send("{E}")
Else
Send("{N}")
Send("{N}")
Else
Send("{l}")
Send("{l}")
Else
Send("{A}")
Send("{E}")
Else
Send("{X}")
Else
Send("{z}")
Else
Send("{B}")
Send("{B}")
Endif```

##### Share on other sites

April Fools day came early this year...you can't have multiple "Else" in an If/Else condition. You can have multiple "ElseIf".

##### Share on other sites

Yeah, Im new and I found that out thx anyways.

Edited by d0pe

##### Share on other sites

There can only be one "Else"

```WinActivate("")
Sleep(1000)

\$Random = Random(3)

If \$Random < 0.7 Then  ; Too many else, to If. How should I do this? :S
Send("{m}")
Send("{m}")
ElseIf \$Random < 0.8 Then
Send("{l}")
Send("{l}")
ElseIf \$Random < 0.9 Then
Send("{R}")
Send("{Enter}")
ElseIf \$Random < 1.0 Then
Send("{Space}")
ElseIf \$Random < 1.2 Then
Send("{I}")
Send("{I}")
ElseIf \$Random < 1.3 Then
Send("{W}")
ElseIf \$Random < 1.4 Then
Send("{S}")
ElseIf \$Random < 1.5 Then
Send("{Q}")
ElseIf \$Random < 1.6 Then
Send("{E}")
ElseIf \$Random < 1.7 Then
Send("{N}")
Send("{N}")
ElseIf \$Random < 1.8 Then
Send("{l}")
Send("{l}")
ElseIf \$Random < 1.9 Then
Send("{A}")
Send("{E}")
ElseIf \$Random < 2.0 Then
Send("{X}")
ElseIf \$Random < 2.1 Then
Send("{z}")
Else ; there can only be one else
Send("{B}")
Send("{B}")
EndIf```

8)

.....Too slow....

... fixed ridiculous code...

Edited by Valuater

##### Share on other sites

Valuater, calling Random() on every ElseIf defeats the purpose of having a condition at all. I'm not sure what this is doing.

##### Share on other sites

I always try to fix the code the OP has, this one turned into a job.... I guess I should have made my own example in the first place

... fixed

lol

8)

Thanks mate

##### Share on other sites

I dont know what youre planning with this code, but it looks to me the situation that calls for a Switch(), not a huge If, ElseIf, ElseIf.......

```WinActivate("")
Switch Random()
Case 0.1 To 0.7
Send("{m}")
Send("{m}")
Case 0.7 To 0.9
Send("{l}")
Send("{l}")
Case 1 To 3
Send("{R}")
Send("{Enter}")
Case 420
Send("Smoke More")
EndSwitch
; etc etc etc```

Edit: If you want to look into more on the Switch() function, make sure you also look at ContinueCase. The example in that help file is more useful than in the Switch() one.

Edited by murdock

## Create an account

Register a new account

×

• Wiki

• Back

• Git