SikuliX: my script reacts too slow when detecting the image, how to improve it? - sikuli

I am making a script that make my character do the fishing automatically
fishAppear = "exclamationMark.png"
getFish = Pattern("pullBackFishRod.png").targetOffset(2,0)
Settings.MoveMouseDelay = 0
# this three lines will click on the fishButton to drop the fish road to the sea
if exists(fishButton):
for x in range(4):
click (fishButton)
After the fish rod drop to the sea, I wait for the fish to get hooked, when the fish get hooked, there will be an exclamation mark show up for about 1 second.
so I wait for the fishAppear image to show up
wait(fishAppear, 2 * 60)
if exists(fishAppear):
for y in range(4):
click(getFish)
The problem now is: the getFish button only show up for like 1 second after the fish get hooked.
When the script detects fishAppear, then it take some time to click on the getFish button, which the getFish button already disappeared.
How can I make the script faster but so it can search the fishAppear image faster?
Thanks!

If the getFish button appears on a specific region of the screen, use Region class to restrict the area of search. Sikuli will react much faster.

Related

How to add mass item to the Mysql in Django

I made a django website and i must add thousands of item to mysql but my mind is now stopped.
When you see the picture, rubik, remedi and point fields available.
I have a sentence forexamle: Headache : Pulsatilla(3)
I click the rubik field choose headache, and then click remedi field choose pulsatilla, and then lastly click point field and choose 3 point.
Everything is good.
But, when i have sentence like this;
ABSORBED, buried in thought : Acon., aloe., am-m., ant-c., arn., bell., bov., calc., cann-i., canth., caps., carl., caust., cham., chin., cic., clem., cocc., con., cupr., cycl., elaps., grat., ham., Hell., ign., ip., lil-t., mang., merc., Mez., mosch., mur-ac., nat-c., nat-m., nat-p., nit-ac., Nux-m., ol-an., onos., op., phel., phos., puls., rheum., sabad., sars., spig., stann., stram., Sulph.
I don't know how to add this easily.
I wanna explain this sentence.
ABSORBED, buried in thought = This is rubik
Acon., aloe., am-m., ant-c., arn., bell., = These are remedi (each one). Bold remedi (for. Acon) = 3 point, italic remedi (for. caps) = 2 point and other remedies = 1 point.
When i use django admin panel it will took too many times because one by one add. And how can i add this rubik and remedies and points easily. I need vision.
Thanks for your supports.

How to avoid sikuli creating a png file when using "with Region"

I have the following code in sikulix (version 2015-01-06)
...
t = wait("total_power.png")
area = Region(t.x+t.w, t.y, 80, 31)
with Region(area):
wait("num_1.png")
....
I find that "with Region" will create a png file in the same directory of the python file. And the png file is the region that I want.
How can I avoid it?
What is is it that you are trying to do here?
Is it that you would like to wait until a window appears, and then look inside that window for another picture to appear?
In that case you alreay have defined the region when you found "t".
"t" is the location of the picture "total_power.png"
For example:
# Wait until the window appears.
p1 = wait("image1.png")
# Find another picture inside the window.
p2 = p1.wait("image2.png")
Edit:
You should have a look here: Link
I think you could use the .right(), if you leave the () empty you take everything.
If fill in a a value you take a part of the screen.
I use .hightlight() when programming to show me what region I am looking at.
You can also use region1.union(region2) to merge 2 region to a new one.
An example:
Image1 = ("image1.png")
class Blue():
def __init__(self):
# Find an image.
LocImage1 = find(Image1)
# Too show the user the region we selected, we can highlight if for 5 seconds.
LocImage1.highlight(5)
# Grab the region to the right of this image.
LocImage1RightSide = LocImage1.right()
# Highlight the region again.
LocImage1RightSide.highlight(5)
# Run class
Blue()

Sikuli interact with more than 1 matching object

Hello so for example I have 4 balls that I must right click on, but when I right click them, nothing about the balls changes, how can I make it so that sikuli right clicks each of the balls and doesn't just get stuck on one of them?
You can use a for loop to search for all the balls.
Then in the for loop you can define what to do with it once found.
For example (Sikuli with Python):
Image_Balls = ()
for x in findAll(Image_Balls):
click(x)
Between the () you need to place a picture of how a ball looks like.
In this example he will find every ball on the screen and click on it.
You can also add a try, catch/exception in the for loop.
Then he will find every ball, and try to right click.
If the try failed, he will execute the catch (exception in python).
And will continue to look for the next ball, until there are no anymore.
Image_Balls = ()
for x in findAll(Image_Balls):
try:
rightClick(x)
except:
pass

In PhpStorm How do you untab to the previous tabstop?

In PhpStorm, when dealing with soft/smart-tabs can I jump back to the previous tabstop with one key press or combo?
I tried Shift+Tab but it doesn't jump back to the tabstop, it jumps back by the size of the softtab.
Here is an illustration where a soft tab is 4 spaces:
Notabs (0 spaces)
••••Tabstop1 (1 Tab)
••••••••Tabstop2 (2 Tabs)
••••••* My cursors is here in between Tabstop 1 + 2
••••••••<- another Tab press moves me to Level2
••••<- I want to get here, back to Level1 (in one key press)
••<- Shift+Tab moves me here (back 4 full spaces, a full soft tab)
In retrospect I can live with just backspacing a 3 to 1 times, and use Shift+Tab when traversing a tabstop or more of distance, but I'm just curious if there is a direct analogy to the way the Tab key works for un-tabbing stuff.
There is a little combo: press Tab, then press Shift+Tab.
It is not in one key press, but it is regardless of number of spaces (1 or 2 or 3) you want to jump over. No need to calculate how many backspaces you need: every time press 2 times.

5 star rating system in actionscript 3

i need to build a 5 star rating for a image gallery. when someone rates a image from the gallery i need to retrieve the rating (say like .5 or 2.5 or 3 or 4.5 or 5)
How can we create something like a 5 star rating system in AS 3.0?
Edited:
not the solutions to send the rating vlues to database... I am looking for the logic to set the rating (stars changing the color indicating the rating has been updated) and get the rating values applied...
Now that the question has completely changed, lets look at displaying some stars:
You can use the Polygon tool to create stars. Select this tool and then in properties, select Options and then Star.
Draw 5 stars on a layer.
Convert these to a MovieClip.
Place them on their own layer. Copy them and then place them onto another layer.
Draw a rectangle that will be the color you want to fill the stars with large enough to cover all of the stars. Put this on another layer and then mask that with one of the star layers. Convert the rectangle to a MovieClip so you can tween it.
Create a tween of the rectangle moving from the left to the right so that it slowly covers the stars.
You should have something like this:
Use gotoAndStop() to stop on a desired frame. In my example, 50 is a full 5-star rating. 25 would be a 2.5 star rating and fill 2 and a half stars. Etc.
Old Answer
I'm keeping this here purely for the sake of people searching for things like "rating system in AS3" which will most likely require the below info.
You'll need to store the ratings in a database. The concept I use (and probably that everyone else uses) is that you store records containing a voter, the rating they assigned and what they voted on eg:
Marty | 3 | hat.jpg
John | 5 | hat.jpg
Simon | 1 | tasty-cereal.jpg
You then request all of the records that relate to a given image, combine all of the ratings found and then divide the total you get by the amount of ratings given. This will yield the average which will represent a rating out of 5.
As an example, the rating for hat.jpg could be found like this in PHP:
<?php
$score = 0;
$query = mysql_query("SELECT ratings.score FROM ratings WHERE image='$image_from_flash'");
while($row = mysql_fetch_assoc($query))
{
$score += $row["score"];
}
$average = $score / mysql_num_rows($query);
echo $average; // This will be sent back to AS3.
?>
To send and receive the ratings, you will need to use URLLoader to communicate with server-side technology, like PHP. This will talk to the database, work out the average as I mentioned above and then send back to AS3 the average rating for you to use.
If you need information about how to work with PHP + AS3 and send information between the two, that's an entirely different question that will require a very detailed answer. You're better off Googling for information about this.
Let me get you started:
Send and load variables with AS3 and PHP
You may want to think about it as a volume slider. for example:
you have a a movie clip of 5 stars that is 100px in width. you make a mask that is 100px wide to cover up the stars. Set up an event listener for MouseEvent.CLICK on the stars movieclip and make the width of the mask whatever the mouseX is relative to the the total width of the clip. something like:
var relativeMouseX:int = mouseX - stars.x; // you'll get a number between 0-100px
so if the value is say 67px then you can do this operation:
67/100 = .67 * 5 = 3.35;
3.35 stars would be the rating.
starsMask.width = relativeMouseX; //makes the mask's width reflect how many stars is showing.