← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #232183]: [How To] set variable value from OCR numerics

 

Question #232183 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/232183

    Status: Open => Answered

RaiMan proposed the following answer:
--1. forget about system resources ...
... we are working with high potential software systems today and taking care for saving system resources is the job of the programmers of these software systems.
So script whatever you like and however you want.

--2. locals vs globals in Python/Jython
in a script all variables are global and hence can be used all over the place.
they are defined by using them the first time on the left side of a =
Local variables only come into existence inside a def(): the parameter variables are local and each variable that inside the def is on the left side of a = (and because of this a local variable can hide a global variable inside the def)

nameGlobal = 1

def function(nameParameter):
     nameLocal = nameParameter +1 # new local variable, not known outside def
     nameGlobal = nameLocal # new local - does not use global var
     return nameLocal

print function(nameGlobal) # prints 2
print nameGlobal # prints 1
nameGlobal = function(nameGlobal) 
print nameGlobal # prints 2

So forget about locals and globals when scripting without using def()'s

When making def()s,
1. all you need inside from outside should be a parameter and 
2. changes to the outside world should be done using the return value. 

To reduce complexity, it is common with rule 1, that globals are used
inside the def on the right side of expressions without having them
specified as parameters (but this is always a risk for hidden problems
later).

--3. your snippet

if exists("win_img.png", 0) and not exists("push_img.png", 0): # see comment
            hands_to_play = hands_to_play - 1
            if betseq == 1:
                   if bet_site == player: bet_site = banker
                   else: bet_site = player

comment: a search for a visual object in the standard waits 3 seconds before giving up. In your version the if would take in the worst case up to 8 seconds (2 * 3secs + search times) to evaluate
using exists(image, 0) returns after the first trial, so my version in the worst case takes 2 seconds.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.