Sign in to follow this  
Followers 0
Dlund

Random Switch

5 posts in this topic

Hey all, I'm trying to create a random switch, but it seems to always default to the else case.

$z = random(0, 3, 0)
switch $z
case 1
for $i = 0 to 12 step -1
clickIt($i);
Next
case 2
for $i = 1 to 12 step 3;
if $i = 13 then $i = 2;
if $i = 14 then $i = 0;
clickIt($i);
Next
case 3
for $i = 1 to 12 step 2;
if $i = 13 then $i = 0;
clickIt($i);
next
case else
for $i = 0 to 12
clickIt($i);
next
EndSwitch

Can you see what may be happening?

Thank you in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

random(0, 3, 0)needs to be random(0, 3, 1)

try "msgbox(0,random(0, 3, 1),random(0, 3, 1))" to see why and read the help file.

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

ah-ah-ah!

Thank you.

One more issue that I'm seein is that my for loops do not seem to bounceback as I would like them to. Ought I change the for loops to while loops and simply run them while i!=12, or can I make the for loops work?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You problem there is your manipulating the variable used in stepping through the for loop, for example:

For $x=0 To 5 ;Maybe ok
$x+=1
Sleep(1000)
ConsoleWrite(@LF&$x)
Next

For $x=0 To 5 ;probably bad
$x-=1
Sleep(1000)
ConsoleWrite(@LF&$x)
Next

and the following will simply fail, the help file will explain why.

for $i = 0 to 12 step -1

and in the case of the following, it will never run 13

for $i = 0 to 12 step 2

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

I caught the first for loop error.

I was hoping that it would hit 13, and run through.. as it does for 12; I have changed those two for loops into while loops, and am still having errors. It seems to be cutting out after 12, not just at 12.

$z = random(0, 3, 1)
switch $z
case 1
for $i = 12 to 0 step -1
clickIt($i);
Next
case 2
$i = 1;
while $i <> 12;
$i=$i+3;
if $i = 13 then $i = 2;
if $i = 14 then $i = 0;
clickIt($i);
wend
case 3
$i = 1;
while $i <> 12;
$i=$i+2
if $i = 13 then $i = 0;
clickIt($i);
wend
case else
for $i = 0 to 12
clickIt($i);
next
EndSwitch

And good it is-- I had $1 instead of $i for my for loops: my lack of sleep is becoming apparent.

Thank you for your help, good sir!

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