Sign in to follow this  
Followers 0
Shifthappens

Random Number not working?

25 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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]

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I'm confused about what the ConsoleWrite line is doing?

Writing to your XBOX 360!

It outputs text to the SciTe log window...

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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]

Share this post


Link to post
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]

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

concatenates example

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

Result will look like:

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

Share this post


Link to post
Share on other sites

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?

Uhh, I did an if statement with 3 different if's all attached by &'s and it worked fine. o.O

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

Uhh, I did an if statement with 3 different if's all attached by &'s and it worked fine. o.O

I would like to see that.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

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]

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