← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #204177]: Sikuli-Script doesn't find the files in Netbeans

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--- 1. do not use the src folder 
You should not use the src folder for your resources, that will not be inside the jar.
put the directory deses/img on the same level as all the Netbeans folders like src, build, diet, lib, ... (hence at the project level)

your images need then be:
    private static final Pattern BUILDING_BASE = new Pattern("deses/img/BUILDING_BASE.png");

this will work  inside Netbeans.

-- 2. using the jar
when you have built the jar, it will be in the dist folder.
Just copy it to the project level and run it from command line being in that directory using
java -jar mystuff.jar
This will work, since deses/img will be found based on the current working directory (you can check this using System.getProperty("user.dir"), which is the directory from where the java command was issued.
if you have the deses/img folder in the same directory as the jar and want to be independent of the location, where the java command is used, you have to put some java code into your stuff, to find out the directory using class loader features where your jar currently is located.
this information can be used then to construct an absolute path to deses/img that can be used with addImagePath.

--- additional comments
you still have some storage usage risks in your code based on redundant calls to methods.

example:


    private void nextOutpost() throws FindFailed, AWTException, InterruptedException {
// this block of local vars is allocated at every call to this method
        final List<Integer> game_saved = Arrays.asList(143, 143, 143);
        final List<Integer> game_saving = Arrays.asList(237, 11, 11);

        final Match match = SCREEN.find(UI_SAVING);
        final Location cTL = match.getTopLeft().offset(5, 5);
        final Robot robot = new Robot();
        final Color color = robot.getPixelColor(cTL.x, cTL.y);
        final List<Integer> rgb = Arrays.asList(color.getRed(), color.getGreen(), color.getBlue());
        if (game_saved.equals(rgb)) {
            SCREEN.click(UI_NEXT);
            SCREEN.wait(3.0);
        } else if (game_saving.equals(rgb)) {
// *** WARNING *** this is a recursive call to this method
            nextOutpost();
        }
    }

So if UI_SAVING is a target with a fixed location (I guess it is), then
these variables should be object variables, that are in fact evaluated
only once at object creation.

Since you use BYMAutomator class to create BYMAutomator it would be a
good idea to have a public constructor where you could put all the
stuff, that is only needed once.

the recursion problem:
If I am right, that the  UI_SAVING is a fixed target on the screen, the a better solution (without any unnecessary memory consumption) would be:

    private void nextOutpost() throws FindFailed, AWTException, InterruptedException {
// ... some code
       while (true) {
          if (game_saved.equals(rgb)) {
               SCREEN.click(UI_NEXT);
               SCREEN.wait(3.0);
               break;
          } else if (game_saving.equals(rgb)) {
               SCREEN.wait(1.0);
               continue;
          }
       }
    }

... and I think, that the if else isn't even necessary

       while (! game_saved.equals(rgb)) {
               SCREEN.wait(1.0);
       }
       SCREEN.click(UI_NEXT);
       SCREEN.wait(3.0);

--- two more things
-- like the SCREEN as class attribute, you should also have a ROBOT as static class attribute 
-- you should compare the Color objects directly, no need to make array lists for that:
instead of
       final List<Integer> game_saved = Arrays.asList(143, 143, 143);
use 
      Color game_saved = new Color(143, 143, 143);
and then
      Color rgb = ROBOT.getPixelColor(cTL.x, cTL.y);
together with
     game_saved.equals(rob)

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