Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trouble loading local resources

Featured Replies

Last time I touched this script there was no trouble, that was like 6 months ago. For some reason trying to load local resources returns null no matter what I try. (I've read through the forums and practically every google result, nothing has worked so far.)

projectfiles.PNG.28ed31a6f2b17070219ed48537dd5fa5.PNG

private Image bg;
private Image bankPaintOn;
private Image bankPaintOff;
private Image startButtonimg;
private Image cursor;
@Override
public void onStart() {
    bg = getImage("images/Background.png");
    bankPaintOn = getImage("images/banking_On.png");
    bankPaintOff = getImage("images/banking_Off.png");
    startButtonimg = getImage("images/Start.png");
    cursor = getImage("images/Cursor.png");
}
    private Image getImage(String path)
    {
        Image img;
        try{
            img = ImageIO.read(this.getClass().getResourceAsStream(path));
            return img;
        } catch(IOException e){
            log(e);
            return null;
        }
    }

[ERROR][Bot #1][04/03 07:46:26 PM]: Error in script onStart(): 
java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at Main.getImage(Main.java:604)
    at Main.onStart(Main.java:208)
    at org.osbot.rs07.event.ScriptExecutor.IiIiIiiiiIII(em:105)
    at org.osbot.rs07.event.ScriptExecutor.start(em:234)
    at org.osbot.ub.run(bx:36)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

embeded resources will not work in osbot you will have to download the images from the web or you can put them in your osbot data folder.

Here is some example code of where I try to load a file from the osbot data directory and if not found I download it from the web and create the cache

https://github.com/battleguard/easyalch/blob/master/src/script/services/PriceLoader.java#L100

Here someones example snippet of a file utility class

 

Edited by battleguard

  • Author
17 hours ago, battleguard said:

embeded resources will not work in osbot you will have to download the images from the web or you can put them in your osbot data folder.

Here is some example code of where I try to load a file from the osbot data directory and if not found I download it from the web and create the cache

https://github.com/battleguard/easyalch/blob/master/src/script/services/PriceLoader.java#L100

Here someones example snippet of a file utility class

 

Thanks for the reply. Is this new that local resources don't work?

Edited by Cloxygen

Resources works for the SDN, but not for local scripts.

To get around this, you'll need two separate pieces of interchangeable code. When you're ready to publish your script, make sure to have the script load assets from the resource folder. Otherwise, have the script load the resource from the data folder. For example:

   /**
    * Attempt to load sprites from resource folder.
    * 
    * @param dir
    *            - (e.g. "/resources/sprites/record-blue.png")
    * @return new {@link ImageIcon} instance
    */
   private static ImageIcon loadImageFromResource(String dir) {
       ImageIcon imageIcon = null;
       try {
           imageIcon = new ImageIcon(ImageIO.read(MacroRecorder.class.getResourceAsStream(dir)));
       } catch (IOException e) {
           //Attempt to print to GLOBAL_LOGGER 
           Logger.GLOBAL_LOGGER.error(e);
       }
       return imageIcon;
   }
   /*private static ImageIcon loadImageFromResource(String dir) {
       ImageIcon imageIcon = null;
       try {
           imageIcon = new ImageIcon(
                   ImageIO.read(new File(String.format("%s/OSBot/Data/%s", System.getProperty("user.home"), dir))));
       } catch (IOException e) {
           Logger.GLOBAL_LOGGER.error(e);
       }
       return imageIcon;
   }*/

 

Edited by liverare

1 hour ago, liverare said:

Resources works for the SDN, but not for local scripts.

To get around this, you'll need two separate pieces of interchangeable code. When you're ready to publish your script, make sure to have the script load assets from the resource folder. Otherwise, have the script load the resource from the data folder. For example:


   /**
    * Attempt to load sprites from resource folder.
    * 
    * @param dir
    *            - (e.g. "/resources/sprites/record-blue.png")
    * @return new {@link ImageIcon} instance
    */
   private static ImageIcon loadImageFromResource(String dir) {
       ImageIcon imageIcon = null;
       try {
           imageIcon = new ImageIcon(ImageIO.read(MacroRecorder.class.getResourceAsStream(dir)));
       } catch (IOException e) {
           //Attempt to print to GLOBAL_LOGGER 
           Logger.GLOBAL_LOGGER.error(e);
       }
       return imageIcon;
   }
   /*private static ImageIcon loadImageFromResource(String dir) {
       ImageIcon imageIcon = null;
       try {
           imageIcon = new ImageIcon(
                   ImageIO.read(new File(String.format("%s/OSBot/Data/%s", System.getProperty("user.home"), dir))));
       } catch (IOException e) {
           Logger.GLOBAL_LOGGER.error(e);
       }
       return imageIcon;
   }*/

 

Use getDirectoryData() from Script

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.