ithelast Posted July 5, 2012 Share Posted July 5, 2012 The idea is that you roll a die. If it comes up with a 6 then you sleep for $RandomSleep. It does not give an error when you run it. So technically the syntax is correct but the logic must be flawed? Global $Paused HotKeySet('{0}', 'Quit') HotKeySet('{\}', 'Pause') Pause() While 1 IF Random (1, 6) = 6 then If Not @error Then $randomsleep = Random(1000, 6000, 1) Sleep($randomsleep) Send("Its Working Rolled a 6") ;This is just to show me that its working and should be deleted or commented out afterwards Else Send("Its Working Rolled a 1 to 5") ;This is just to show me that its working and should be deleted or commented out afterwards Endif Endif WEnd Func Pause() $Paused = Not $Paused While $Paused Sleep(100) WEnd EndFunc ;==>Pause Program Func Quit() Exit 0 EndFunc ;==>Quit Program Link to comment Share on other sites More sharing options...
twitchyliquid64 Posted July 5, 2012 Share Posted July 5, 2012 I do not understand what kind of help you are asking for. Please fill in the following to help us help you. I am Trying to create a program which achieves _____________________________ Your program is confusing TBH. Try and simplify the logical flow of execution. Also, in future, enclose your code in 'code' tags for readability. Lastly, use the command ConsoleWrite() to see if something works, not Send(). ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
John Posted July 5, 2012 Share Posted July 5, 2012 Your first test is: "IF Random (1, 6) = 6 then". This should never return an @error so that condition will never happen, which then forces it to always act as though it rolled less than a 6. Try this: While 1 IF Random (1, 6) = 6 then $randomsleep = Random(1000, 6000, 1) Sleep($randomsleep) Send("Its Working Rolled a 6") ;This is just to show me that its working and should be deleted or commented out afterwards Else Send("Its Working Rolled a 1 to 5") ;This is just to show me that its working and should be deleted or commented out afterwards Endif WEnd However, depending on what are are trying to accomplish it still might not work properly for two reasons. First, you are rerolling Random after rolling a 6. That means your actual sleep time ($randomsleep) will probably be less than 6. Second, you never enabled the integer flag on initial Random. This means the odds of rolling a 6 is near zero, since the number you roll can be any number (float) between 1 and 2, or any other valid integer given. To fix both of these it would look more like: While 1 $randomsleep = Random(1000, 6000, 1) IF $randomsleep = 6 then Sleep($randomsleep) ConsoleWrite("Its Working Rolled a 6") ;This is just to show me that its working and should be deleted or commented out afterwards Else ConsoleWrite("Its Working Rolled a 1 to 5") ;This is just to show me that its working and should be deleted or commented out afterwards Endif WEnd That may or may not be what you are trying to accomplish. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 5, 2012 Share Posted July 5, 2012 1. Change this: IF Random (1, 6) = 6 then, to this: If Random (1, 6, 1) = 6 Then.2. Don't call the Pause function, except in the HotKeySet, IOW, don't call it right before the While..WEnd loop, because then the script 'pauses' as soon as it's run..3. Get rid of the If @error line and it's EndIf.4. Get rid of the curlies in both the HotKeySet lines.5. Exit 0 is the same as Exit, as 0 is the default. So, no change is necessary, but.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
ithelast Posted July 5, 2012 Author Share Posted July 5, 2012 (edited) I do not understand what kind of help you are asking for. Please fill in the following to help us help you. I am Trying to create a program which achieves _____________________________ Your program is confusing TBH. Try and simplify the logical flow of execution. Also, in future, enclose your code in 'code' tags for readability. Lastly, use the command ConsoleWrite() to see if something works, not Send(). Hey twitchyliquid64 1. Thanks for the ConsoleWrite() tip that is super handy. 2. I am trying to create a program that will sleep for X amount of time given a specific die roll. "Example if you roll a 6 then you take a Random 5-10 Minute Break". 1. Change this: IF Random (1, 6) = 6 then, to this: If Random (1, 6, 1) = 6 Then. 2. Don't call the Pause function, except in the HotKeySet, IOW, don't call it right before the While..WEnd loop, because then the script 'pauses' as soon as it's run.. 3. Get rid of the If @error line and it's EndIf. 4. Get rid of the curlies in both the HotKeySet lines. 5. Exit 0 is the same as Exit, as 0 is the default. So, no change is necessary, but.. Thank you somdcomputerguy I made some modifications based on your suggestions and the script is running! The problem I am running into is that the Sleep duration is very short (almost zero). Global $Paused HotKeySet('0', 'Quit') HotKeySet('', 'Pause') While 1 If Random (1, 6, 1) = 6 Then $randomsleep = Random(10000, 60000, 1) Sleep($randomsleep) ConsoleWrite("Its Working Rolled a 66666666666666666666");This is just to show me that its working and should be deleted or commented out afterwards Else ConsoleWrite("Its Working Rolled a 11111111111111111111");This is just to show me that its working and should be deleted or commented out afterwards Endif WEnd Func Pause() $Paused = Not $Paused While $Paused Sleep(100) WEnd EndFunc ;==>Pause Program Func Quit() Exit EndFunc ;==>Quit Program Thanks John I also tried inserting this into my modified code but it seems to give the same output, in that the sleep timer does not seem to be taking affect While 1 $randomsleep = Random(1000, 6000, 1) IF $randomsleep = 6 then Sleep($randomsleep) ConsoleWrite("Its Working Rolled a 6") ;This is just to show me that its working and should be deleted or commented out afterwards Else ConsoleWrite("Its Working Rolled a 1 to 5") ;This is just to show me that its working and should be deleted or commented out afterwards Endif WEnd Edited July 5, 2012 by ithelast Link to comment Share on other sites More sharing options...
ithelast Posted July 6, 2012 Author Share Posted July 6, 2012 (edited) Eureka!I had to define the variable $randomsleep as a global variable (I think that is the term) then I can just call (I think that is the term also please correct me if I am wrong) it when I want to use it.Global $PausedHotKeySet('0', 'Quit')HotKeySet('', 'Pause')$randomsleep = Random(60000, 300000, 1) ;This is the guy I needed to declare. It says for the variable $randomsleep = do this. In this case roll a random number between 60000 and 300000. Also the old numbers I was using to test were too large apparently Autoit has a limit for random numbers?While 1If Random (1, 50, 1) = 50 Then ;ConsoleWrite("Its Working Rolled a 66666666666666666666");This is just to show me that its working and should be deleted or commented out afterwardsSleep($randomsleep)Else ;ConsoleWrite("Its Working Rolled a 11111111111111111111");This is just to show me that its working and should be deleted or commented out afterwardsSleep($randomsleep)EndifWEndFunc Pause()$Paused = Not $PausedWhile $PausedSleep(100)WEndEndFunc ;==>Pause ProgramFunc Quit()ExitEndFunc ;==>Quit ProgramThanks for all the help guys really appreciate it! Edited July 6, 2012 by ithelast Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now