Sign in to follow this  
Followers 0
LoWang

AdlibRegister - is it possible to make the script return from func?

7 posts in this topic

Hello I have some GUI automation script with an Adlib registered function which fires from time to time and if one global variable does not change enough then it tries to reset some program window because it probably mean something has gone wrong. The problem is that it does not really work when the main program is not in the main loop but in some Func instead waiting for something which then does not come because the Adlib functions changes the environment. So my question is if there is any possibility to make the currently being executed Function return back to main loop by the adlib? Of course I cannot predict when the Adlib fires so there is no way to have if conditions all around to check for some global variable like if $getback then return. Basically I want to have the whole program reset to some basic state when adlib func fires it. Is that possible by any other means then having some paralel running script which would substitute that Adlib function and exit and rerun the main script when necessary? Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm not sure what you mean exactly, but you can have adlib trigger a reset type event by setting a global flag or sending some kind of message to a dummy control or something similar. It sounds like you need to write a reset function.

Edited by czardas

Share this post


Link to post
Share on other sites

In the past, I've come to the same place as you, hoping to break some function or loop with adlib, and I have to say every single time it was because I coded myself into a corner.

I say this not to be a pain, but every time I went back to the drawing board and made better, more stable code and didn't have to rely on things like adlib, and I was MUCH better off in the long run.

I have once or twice used adlib to set some global $var and checked that in my func, but you said that doesn't work for you.

I don't know if anyone else has an elegant solution, and again I don't want to come off as annoying or unhelpful, but I think the real solution to your problem is going to be changing the way your code behaves, so that you can check variables better, so you don't get yourself into that corner in the first place.

Whatever you end up doing or deciding, please let us know.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

LoWang,

If I have understood your requirements correctly I do not believe that you can use an Adlib function in this way. The running function has to end somehow and it must be from within its own code - as is shown in the Interrupting a running function tutorial in the Wiki. If your function does not check for a termination flag I do not see how it can end. :)

Sorry to be so negative, but you have run up against one of the more intractable problems of a single threaded process. How much time is spent in these functions as compared to the main loop? Would it be worth stopping the Adlib when in the functions - or at least those which do not lend themselves to looking for a flag? You mention that the function might be waiting for something - that is the ideal moment to look. ;)

If you spend most of the script in the functions (and remember we are talking real time here not relative amount of code) then you may well have to use your idea of a separate script looking at a value stored somewhere else and restarting the main script. There a number of inter-script communication UDFs out there - my personal favourite is trancexx's MailSlot. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

To me the answer is to scrap Adlib*

If the function called by it is only safe while at a certain point in your script logic then you should run

that function from there. It is adlib* seems just to be a timer, so just create a timer check at the

safe point in your code, and run the function if your required time has passed (whatever you set Adlib to).

If that does not make sense, have a look to see what I mean

This code will not work as it is, just to assist my unwordyness.

Global $tine = _Now()
Func _MainSafePoint()
If _DateDiff($tine) = 60 Then
  _AdlibFunction
  $tine = _Now()
EndIf
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Wow thank you all for your comments:) I am glad I started an interesting discussion.

I know that this concept I am talking about would not be a very good practice if I was actually doing some important project:) I will tell you what it is: a little automation attempt for a web based game in flash. It consists of a main loop which checks for some events which happen when the game is idle (or no action is happening in it) and a lot of functions designed to do certain things in the game which I keep adding. I use the great ImageSearchDLL.dll library to find certain patterns on the screen and that way I can script things like:

find that picture, click on it, wait for another picture to appear, click on that

so the code can be quite simple and easy to read if everything works as expected of course :) The problem is that sometimes something unexpected happens and it can be for example when the mouse click is just ignored by the web browser - this happens quite a lot especially when using mouseclick with speed 0, differs between browsers and I frankly don't understand WTH. When I suspect that it might happen in some situation I cannot just use mouseclick and consider it done. I have to make some kind of loop which keeps clicking until something appears or disappears and then it continues. Of course I have to add some sleep and counter to end the loop in case the expected action never happens and handle this situation accordingly. This is awfully complicated and sometimes it cannot be easily determined if the click really worked and the game really got into the next expected state so the script can continue. Sometimes there can be some mysterious problem which causes the game to show error message or my wifi connection suddendly stops working or there is an antivirus scheduled scan or whatever windows system message which covers the screen so certain elements are suddendly invisible.

There is simply a lot of possible problems which cannot be easily predicted and those clicking functions can get stuck in almost any place. I thought that trying to handle all possible situations in all places where something could go wrong would just triple the size of my code and once clear script would look awfully bloated and hard to understand. Also any unnecessary checking slows down the execution because the pattern searching is quite CPU intensive so I would sacrifice speed for a bit more reliability. I do have a function which handles some known situations in the main loop, but it is of no use if the script gets stuck on something in one of the functions. That is why I thought I will use this Adlib because those unexpeted situations are not that frequent and this will run always even if some function gets into an infinite loop or something. Some functions get nested quite a bit by calling more functions from within so if there was some unexpected problem in the last called func then I would have to keep checking all the return values and keep track what and where got wrong all the way back the the main loop and then handle it accordingly which could be quite complex if done really thoroughly... Hm but the more that I think of it, the more I see that another paralel script would be the only reliable long term solution to this :-] it could also make a screenshot of a screen in case something unexpected happened so next time I could handle it properly somewhere in the code without doing this kind of reset.

Thank you Melba for that mailslot, I will check it. However I already made myself some easy to use functions to do interprocess communication via UDP, so I guess I will stick with this. Another very simple communication between processes could be using the system registry which is IMHO more suitable and fast then using files for example.

So that's it guys. I make this just for myself to save time which would be otherwise wasted by stupid robot-like clicking ;) And of course I hope to learn something from it too.

Edited by LoWang

Share this post


Link to post
Share on other sites

As quickly as you started a conversation you ended it. Rules. Game bots. Read that part. It's important. Thread locked.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0