Jump to content

Random Number not working?


Recommended Posts

I am using $Move = Random(0,3,1).

At the beginning of the script, I set Move to 0 just so it starts at something.

The $Move = Random(0,3,1) is in a loop so it should keep changing it.

So there are four possible moves I have, checking if $Move = 0, 1, 2, or 3, but for some reason only 0 works.

Any ideas?

Link to comment
Share on other sites

The random function does indeed work as you are describing, as proven by this test example:

HotKeySet("{ESC}","_Quit")
While 1
    $move=Random(0,3,1)
    ConsoleWrite("$move=" & $move & @LF)
WEnd

Func _Quit()
    Exit
EndFunc

There must be something else going on. Post the rest of your code and maybe we can help you find it.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

The random function does indeed work as you are describing, as proven by this test example:

HotKeySet("{ESC}","_Quit")
While 1
    $move=Random(0,3,1)
    ConsoleWrite("$move=" & $move & @LF)
WEnd

Func _Quit()
    Exit
EndFunc

There must be something else going on. Post the rest of your code and maybe we can help you find it.

I'm confused about what the ConsoleWrite line is doing?
Link to comment
Share on other sites

It puts the input into the lower pane in Scite for easy reading of results.... If you are not using Scite (or some other IDE) then you could easily replace the ConsoleWrite() with a similarly formatted MsgBox() or ToolTip()

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

It puts the input into the lower pane in Scite for easy reading of results.... If you are not using Scite (or some other IDE) then you could easily replace the ConsoleWrite() with a similarly formatted MsgBox() or ToolTip()

Correction, if you aren't using an IDE, please get one immidiately.

A direct download link to SCITE4AutoIt:

http://www.autoitscript.com/cgi-bin/getfil...iTE4AutoIt3.exe

Trying to program without an IDE is like trying to drive a car without a steering wheel. Just don't do it.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Trying to program without an IDE is like trying to drive a car without a steering wheel. Just don't do it.

Tell that to my C++ teacher at Bowling Green State University, we had to do all of our lessons through telnet, and that was just earlier this year. She had no clue what Bloodshed Dev C++ was.

Link to comment
Share on other sites

Correction, if you aren't using an IDE, please get one immidiately.

A direct download link to SCITE4AutoIt:

http://www.autoitscript.com/cgi-bin/getfil...iTE4AutoIt3.exe

Trying to program without an IDE is like trying to drive a car without a steering wheel. Just don't do it.

- The Kandie Man ;-)

I already have Scite :)

Here's the code i'm using.

$Move=Random(0,3,1)
  $Colour = PixelGetColor(503,1)
  if $Colour = $Jim & $Move=0 Then Send("5" , 1)
  if $Colour = $Jim & $Move=1 Then Send("8" , 1)
  if $Colour = $Jim & $Move=2 Then Send("1" , 1)
  if $Colour = $Jim & $Move=3 Then Send("0" , 1)
Link to comment
Share on other sites

Bad syntax there caller...

$Move=Random(0,3,1)
  $Colour = PixelGetColor(503,1)
  if $Colour = $Jim & $Move=0 Then Send("5" , 1)
  if $Colour = $Jim & $Move=1 Then Send("8" , 1)
  if $Colour = $Jim & $Move=2 Then Send("1" , 1)
  if $Colour = $Jim & $Move=3 Then Send("0" , 1)

& concatenates 2 strings together

&& = AND

Link to comment
Share on other sites

Bad syntax there caller...

$Move=Random(0,3,1)
  $Colour = PixelGetColor(503,1)
  if $Colour = $Jim & $Move=0 Then Send("5" , 1)
  if $Colour = $Jim & $Move=1 Then Send("8" , 1)
  if $Colour = $Jim & $Move=2 Then Send("1" , 1)
  if $Colour = $Jim & $Move=3 Then Send("0" , 1)

& concatenates 2 strings together

&& = AND

Sorry, but what do you mean by concatenates? I used & on something like this before and it worked.
Link to comment
Share on other sites

Try using a select-case statement instead.. simpler to understand and faster performance too

$Move=Random(0,3,1)
$Colour = PixelGetColor(503,1)
Select
    Case $Colour = $Jim and $move = 0
        Send("5" , 1)
    Case $Colour = $Jim and $move = 1
        Send("8" , 1)
    Case $Colour = $Jim and $move = 2
        Send("1" , 1)
    Case $Colour = $Jim and $move = 3
        Send("0" , 1)
EndSelect
Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Sorry, but what do you mean by concatenates? I used & on something like this before and it worked.

concatenates example

$x = "Hey"
$y = "There"
MsgBox(0,"", $x & $y)

Result will look like:

HeyThere

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Sorry, but what do you mean by concatenates? I used & on something like this before and it worked.

You mean you did something like:

$string1 = "Fail"
$string2 = "Blue"

If ($string1 = "Success") & ($string2 = "Orange") Then
;Do Stuff
MsgBox(0,"","TEST")
EndIf

And then you never wondered why it was ALWAYS TRUE?

Link to comment
Share on other sites

I'm sorry, but i'm a bit confused, isn't that the same as and?

& does not equal AND

Look at the help file for IF...THEN

The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I would like to see that.

It did work when I had them all, but I don't feel like messing with my script it's disorganized enough as it is.

Will test spook's script from Select Case earlier, and also, I checked out the If.Then help file, but didn't see anything in mine that was really relevant to the & sign.

Link to comment
Share on other sites

I checked out the If.Then help file, but didn't see anything in mine that was really relevant to the & sign.

That's the point... & is not listed as an acceptable boolean or logical statement

[edit] semantics

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

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...