[How to] Persistent Script

Asked by Javier Gonzales Rodriguez

Hello there,

Can someone help with information/examples about to create a persistent script and run it at the same time that my sikuli script?

Let me explain a little bit why i need this ...

I have a loop with 15 lines of code, the code line number 5 looks for an image on the screen that appears randomly and then disappear, so ...
The image appear and my script already jump to the line 6, so am missing the image, this is on a loop so, sometimes i get it, sometimes i miss.

I wish to create a Persistent Script that will be focusing on get the images while my other script will prepare the scenario for the persistent script.

Am using Python, Linux Mint 20, Java JDK 14, Sikulix IDE

Regards!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Prabhas Koya (prabhas1) said :
#1

can you tell what actually you want to ask?
do you want to loop over to find if image exists or not and do according to it?
a regular image check....!

Revision history for this message
Javier Gonzales Rodriguez (stonegarden21) said :
#2

Hi Prabhas,

I wish to know how to run a persistent script ... is like to run two scripts at the same time on the sikulixIDE, right now I have one script running.

Regards!

Revision history for this message
Prabhas Koya (prabhas1) said :
#3

you can import one script to other script and run both .But if you want to run differently , running two at a time that is not possible .Better way is to import and create a script with your running script so that you can run both in ide.

Revision history for this message
masuo (masuo-ohara) said :
#4

@Javier Gonzales Rodriguez
feature "Observing Visual Events in a Region" is useful in some cases.
https://sikulix-2014.readthedocs.io/en/latest/region.html?highlight=onappear#observing-visual-events-in-a-region

Revision history for this message
Javier Gonzales Rodriguez (stonegarden21) said :
#5

thanks for your reply,

Well, i was looking something like this:
https://www.autohotkey.com/docs/commands/_Persistent.htm

I didnt try just creating a loop on the new script and importing it from the main script honestly, i thought that maybe there was another way like the information on the link.

Masuo, thanks man, I forget the observing, am gonna make some tests, it might work too.

Thanks!

Revision history for this message
Javier Gonzales Rodriguez (stonegarden21) said :
#6

Hi @masuo,

Am testing the observer function but it is not working properly.

this is my code:

#MyHandler is going to call "Trade()" function only
def MyHandler(event):
    try:
        Trade()
        pass
    except:
        pass

#So my observer has one region assigned and it is running in background.
msgReg.observeInBackground()
onAppear("1597989280191.png", MyHandler)

#I stop the observer like this.
msgReg.stopObserver()

the msg error that i get is this "[error] Region: observe: Nothing to observe (Region might be invalid): R[49,635 386x69]@S(0)"
I tried with a region small and am sure that the image that am looking is right there (clearly).

Any reason why is not working, am i doing it wrong?

Regards!

Revision history for this message
Best RaiMan (raimund-hocke) said :
#7

correct sequence:

#MyHandler is going to call "Trade()" function only
def MyHandler(event):
    try:
        Trade()
        pass
    except:
        pass

#So my observer has one region assigned and it is running in background.
msgReg.onAppear("1597989280191.png", MyHandler)
msgReg.observeInBackground()

#I stop the observer like this.
msgReg.stopObserver()

read the docs about the feature

Revision history for this message
Javier Gonzales Rodriguez (stonegarden21) said :
#8

Hi there,

now it is working way better.

def MyHandler(event):
    try:
        Trade()
        pass
    except:
        pass

msgReg.onAppear("1597989280191.png", MyHandler)
msgReg.observeInBackground(FOREVER)

msgReg.stopObserver()

Revision history for this message
Javier Gonzales Rodriguez (stonegarden21) said :
#9

Thanks RaiMan, that solved my question.