BlackPhoenix Posted February 13, 2009 Posted February 13, 2009 Hello everyone, What I try to do is make a script that executes 4 different functions and sets a timer after it went through one of those functions. If the timer has not reached the value that is needed to go through the function it must skip it and check for the next timer to use the next function. I tried a lot of things, but just cant get it right. I would appreciate it if someone can help me ^^ ps. I'm still a beginner This is my current code: #include <Timers.au3> $countmed = 1000 $countauto = 1000 $countrijles = 1000 $countschiet = 1000 While $iLoop If $countmed >= 10 then SteelMedium();if the counter is on 10 seconds or higher excute function again If $countmed >= 10 then global $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000) If Not $iLoop Then ExitLoop If Guictrlread($checkbox0) = 4 AND $countauto > 300 then SteelAuto();if checkbox for this function is checked and timer is over 300 seconds execute this If Guictrlread($checkbox0) = 4 AND $countauto > 300 then global $beginsteelauto=TimerInit(),$difsteelauto=TimerDiff($beginsteelauto),$countauto= int($difsteelauto/1000) If Not $iLoop Then ExitLoop If Guictrlread($checkbox)= 4 AND $countrijles > 90 then Rijbewijs() If Guictrlread($checkbox)= 4 AND $countrijles > 90 then global $beginrijles= TimerInit(),$difrijles=TimerDiff($beginrijles),$countrijles= int($difrijles/1000) If Not $iLoop Then ExitLoop If Guictrlread($checkbox2)= 4 AND $countschiet > 60 then Shootingrange() If Guictrlread($checkbox2)= 4 AND $countschiet > 60 then global $beginschiet= TimerInit(),$difschiet=TimerDiff($beginschiet),$countschiet= int($difschiet/1000) If Not $iLoop Then ExitLoop If $delayI= 1 then Sleep ($pauset) If Not $iLoop Then ExitLoop WEnd
someone Posted February 13, 2009 Posted February 13, 2009 The code is a little confusing, it might make more sense to see the whole code, but here are a couple things to change... You have multiple If/then statements with the same conditional. In these lines; If $countmed >= 10 then SteelMedium();if the counter is on 10 seconds or higher excute function again If $countmed >= 10 then global $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000) The while statement is always going to do SteelMedium if $countmed is >=10. Depending on what SteelMedium does, your code may never get past that point. If SteelMedium when finished returns to the while loop, the loop will advance, but its not very clean. Also if SteelMedium changes the value of $countmed to lower then 10, the next if/then statement won't be true (maybe that is what you want, maybe it isn't). Also, doing this - $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000) is always going to make $countmed = 0. You are starting a timer, then immediately stopping it, dividing by 1000, and rounding to the nearest whole number. Clean up that stuff first, and see if it makes a difference in your code vs expectation. If that doesn't work, post the cleaned up code, (a reproducer if possible), what you did, what happened and what you were expecting to happen. Also, even though coding like this; If $countmed >= 10 then global $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000) works, its cleaner and easier to read making it a multi line if statement, like this; If $countmed >= 10 then $beginmedium= TimerInit() $difmedium=TimerDiff($beginmedium) $countmed= int($difmedium/1000) endif Welcome to the forum While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
BlackPhoenix Posted February 13, 2009 Author Posted February 13, 2009 The code is a little confusing, it might make more sense to see the whole code, but here are a couple things to change...You have multiple If/then statements with the same conditional. In these lines; If $countmed >= 10 then SteelMedium();if the counter is on 10 seconds or higher excute function again If $countmed >= 10 then global $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000)The while statement is always going to do SteelMedium if $countmed is >=10. Depending on what SteelMedium does, your code may never get past that point. If SteelMedium when finished returns to the while loop, the loop will advance, but its not very clean. Also if SteelMedium changes the value of $countmed to lower then 10, the next if/then statement won't be true (maybe that is what you want, maybe it isn't).Also, doing this - $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000) is always going to make $countmed = 0. You are starting a timer, then immediately stopping it, dividing by 1000, and rounding to the nearest whole number.Clean up that stuff first, and see if it makes a difference in your code vs expectation. If that doesn't work, post the cleaned up code, (a reproducer if possible), what you did, what happened and what you were expecting to happen. Also, even though coding like this; If $countmed >= 10 then global $beginmedium= TimerInit(),$difmedium=TimerDiff($beginmedium),$countmed= int($difmedium/1000)works, its cleaner and easier to read making it a multi line if statement, like this;If $countmed >= 10 then $beginmedium= TimerInit()$difmedium=TimerDiff($beginmedium)$countmed= int($difmedium/1000)endifWelcome to the forumTnx, Yeah I cleaned it up a bit now, and I think i might have an idea, if this works or doesn't I will report back
myspacee Posted February 13, 2009 Posted February 13, 2009 Hello to all, need similar thing. I've a script that monitor directoy after 11 PM Before i want that script do some thing, and the wait for 11 PM. any idea How : - check time in a while cicle - to 4 AM until 6 PM do nothing - when 6 PM do a task and wait until 11 PM ? thak you to teach me _datediff use . M.
BlackPhoenix Posted February 13, 2009 Author Posted February 13, 2009 I still can't get it to work, I think I'm having a wrong code for what i want. I know what I want but don't know how, so i'll explain here: First the code runs through a loop with 4 functions, those functions do not influence any variables. After that it starts a timer for every function, and waits till that timer reaches a certain value. If it doesn't reach that value it just checks if one of the other timers has reached that value. For example 30 seconds, 40 seconds, 1 minute, 2 minutes. After the code waited for 30 sec e.g. 40 sec, 1 min, 2 min, it restarts the timers. I hope i made it clearer for you
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