SorryButImaNewbie Posted April 8, 2015 Share Posted April 8, 2015 Hello! I was just wandering if is there some innate problem with how I usually structure my script, or is there a general better practice. I usually do it as follows, I create a GUI (after includes, Opts, Global constants, arrays, or just decleare variable names) either with another program, or with autoit code (never like creating GUI from code) then I start an "Idle" function with a Sleep(200) My first question, how much sleep should I usually give to my script? What could influence this value? Then after the sleep in the Idle I declear "checks" to see if something happened in the GUI or not like this: Func Idle() While 1 Sleep(200) If $fTestRun Then ;Test() EndIf If $fExitRun Then _Exit() EndIf ;Other "Runflags" WEnd EndFunc ;==> Idle by "Runflags" I mean that most of the time my controls change the value of a runflag, and when that value is true (at the start of the script I set them all to false) it runs the corresponding function, and at the end of the function it changes back to false. It can be used to place "check points" in to the function, to see if the flag is still true, with this I can use them as a kind of stop points (if its needed) Of course there could still be functions that has no such flags, since they only run in special events, within another function or something else. I'm just curious If I do something terribly wrong with this kind of general setup, or should I do something in a different way? Do you have somekind of structure like this? or a completly different one? I doesn't seem to have any problems with this, but if there is a better way I may try to change my habbit Have a nice day! Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 i build my scripts with onevent tuned on, my loop which keeps gui alive is very short, and its easy to add ton of controls and add functionality to them with ease. try and learn here: https://www.autoitscript.com/autoit3/docs/guiref/GUIRef_OnEventMode.htm SorryButImaNewbie 1 Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 I too enable onevent mode, but I usually just use it to the "System Events" Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 (edited) well you can add events on the buttons/labels/anything as well, in a convenient place, right next to the control. i started scripting without this metod, but after my scripts started to get tons of controls, i switched to this onevent metod, and i felt happy (because doing them all in one big loop started to be a pain). about the sleep - its just how fast script "rechecks" for something to do. 100 is prentiful time btw whats with the runflags? why you think you need them? you wont get any other function in the middle of one function already running. except for somecases, but still, im curious Edited April 8, 2015 by Zobengrauzis Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 btw whats with the runflags? why you think you need them? you wont get any other function in the middle of one function already running. except for somecases, but still, im curious I thought that this method will allow me to easly see through my script, and make it more "structured" also I can stop a function with another button (which turns every flag to false) if there is a need for that kind of thing Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 well i see ure point, thou i don't see where this effort could pay off. Do it if you want, but i would do it if i saw a real need for it. Only if you are making a huge script where many adlib functions go paralelly, otherwise - hard exit is always a thing, or just pausing a script too. Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 What do you mean by hard exit? Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 clicking on ure running scripts trayicon and restarting the script if you need it to stop in middle of something. Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 You mean Exit from the script and then restart it? Thats something what I would want to avoid Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 (edited) well, in genereal, yes. but functions which may be needed to be stopped manually - and work hard to implement this (btw flag value in the start only prevents it from starting. you will need those flags all over the function to be able to stop in middle (thou there is a smart way to do it, i read it somewhere, but cant recall now)) - well i would want to see how you do it when your code reaches many thousands of rows Edited April 8, 2015 by Zobengrauzis Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 I usually goes through the function and specify "logical" stop points and put a check there, yes this cause extra code, but I don't yet know a better way now. Also My code is naturaly bigger then most here (since I'm green) but I'm getting better. My first script was around 140 thousands row long, just when I finished it, we got an update (which we didn't asked for ) and with it the entire program I had to automatet was changed... So I had to rewrite the thing and it became 40k lines, so I definetly improved Link to comment Share on other sites More sharing options...
Zobengrauzis Posted April 8, 2015 Share Posted April 8, 2015 well i just stumbled on ure old posts and started to see. in ure place i would be too laizy to put the logical stops, would just make temporary data containers, and in stead of making points in functions to stop them, would make a call which restarts the script with reading temporary data to continue from where the user left. but cant tell if it would be a good practice, cuz i dont know ure script, only my thoughts - only my laizy way of doing things but yea. i got updates (many) in my time too. with time i learned to make solid sceleton functions and when the time came - changed muscle functions, which were nice and separate and easy to replace/modify. Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 8, 2015 Author Share Posted April 8, 2015 Being lazy is the drive for all we humans achived so far 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