Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Persistent Preferences/settings in Java applications


    yeeter

    Recommended Posts

    So let me first state I am not sure if this is allowed on SDN scripts


    What is it?

     

    Well application preferences are like a prebuilt way to save data from applications or scripts.  I noticed someone people in my DMs saving files by just exporting a text file or configuration file.  While that works this method condenses it and just looks cleaner imo.

     

    How do you use it yeeter?

     

    Well I write some really ass scripts for my own personal farm between a few clients.  These preferences are accessible from from anywhere, and any time.  So My main farming script I load it the first time manually and configure any settings that need configured and hit save.  Once my bot manager is configured and it spools up bot instances and loads the scripts each bot will be running the scripts them selves will reach out to read these preference files I had set initially meaning I don't have to set up the same script a few hundred times

     

    BUT YEETER WHAT ABOUT QUICKSTART?!?!?!

     

    Yeah you could practically do the same thing with quickstart but due to the shitshow that is my farm different clients have different quickstart abilities and this way was just easier instead of my having to configure my manager to output 100000 variants of settings for quickstart.  So now no matter what client my scripts are running on it can reachout and read these preference files.  The same could also be done with a .txt file but like I said above this was just better for my usecase imo.

    How to start

    Well to start we need to create our preference object.  I just do this as a global variable so I can access the same instance anywhere in the program.  

    	public Preferences pref = Preferences.userRoot().node(this.getClass().getName());

    this creates the Preferences object called pref and sets the root node to the name of my class.  You can manually set this to whatever you like so say that individual farms name or just a general term so you can access them from anywhere.  I generally have 2 areas I store perfs in and that being the class's name to configure the scripts its self then a general one for that system so I can access some general data I need for my operations. 

    	public Preferences pref = Preferences.userRoot().node("ANY NAME YOU FUCKIN WANT");

    Saving a preference

     

    So now that we have our preference object we can start saving any settings/data we want.  This data will be presistent so any other bot running the same script will have access to this data, if we shut the computer down and turn it back on the data will still be there etc.  It is probably a good idea to not save shit here you will change 100000000 times during the script.

    We can save data by calling one of the following methods.

    		pref.put(key, value);
    		pref.putBoolean(key, value);
    		pref.putByteArray(key, value);
    		pref.putDouble(key, value);
    		pref.putFloat(key, value);
    		pref.putInt(key, value);
    		pref.putLong(key, value);

     

    So clearly we need a key and a value sorta like a hashmap with key, value pairs except this is persistent while a hashmap would be nuked once the script stops.

    You can call this .put(key, value) methods at point in your script I put some in my stop method but I have placed others in my bank operations etc.  So just for an example lets say I want to get the last game message received and save it.  That way next time we load the script we can be told what said game message was.  We could do the following.

    	@Override
    	public void onGameMessage(Message message) {
    		pref.put("last_message", message.getMessage());
    	}

    So now we saved the last game message with the key "last_message".  I generally will declare global constant variables with the key names to avoid possibly fucking up but thats personal preference.  

    So for an example I enabled the ability for me to use the mouse while the script runs and examined some random objects in my inventory.  The last item I inspected was the chiefs hat and that resulted in the game message "What a silly hat.".  So if I call the "last_message" preference the String it returns to me will be "What a silly hat."

     

    q2B7r7V.png

     

    Calling saved preferences

     

    So now that we have saved preferences its time to do some useful shit and call the saved preferences to get the data they are associated with.  We can call them by calling similar methods to the .put(key, value) methods we used earlier to save the data.

    	pref.get(key, def);
    	pref.getBoolean(key, def);
    	pref.getByteArray(key, def);
    	pref.getDouble(key, def);
    	pref.getFloat(key, def);
    	pref.getInt(key, def);
    	pref.getLong(key, def);

    Unlike the .put(key, value) method we use .get(key, def). .get() requires a key, and a default parameter.  The key being the identifier for trhe data we saved (last_message) and the default being the fallback or default data in case our key is not found.  

    So going along with the above example lets say we want to print out the last saved message from the last client that closed.  That being saved in our last_message key and can be done like so.

    @Override
    public void onStart() {
    	log("last_saved message = " + pref.get("last_message", "No message was saved last time."));
    }

    This results in the last message being printed out.  If I run other bot instances, or other scripts making the same call they will print the exact same thing into the console.  If we were to have not set the last_message key before hand we would had printed out the default message we provided "No message was saved last time.".

     

    FI9td2A.png

     

    But yeeter that example was complete TRASH!


    Yeah you are 110% correct.  This is simple enough I couldn't justify coming up with a complex GUI to save data between instances to prove its usefulness.  If you find your self needing access to a few pieces of data across multiple bot instances, between multiple scripts, between multiple applications and don't want to fuck with sockets for a few small things this is the thing for you.  A bare minimum use case is 3 lines. Declaring the object, saving the data, calling the data.  This could be a mules name, location for bots to end on, a setting flag on the a script, and whatever you can think of.  This all could be done via quickstart with the -params tag but for my setup I was tired of formatting argument strings for 10000 small things so this cut out that headache from a farm management side.  Here is the link to Nezz's quickstart guide definitely worth the read and contains examples of the -params tag being used to pass some details to the script he is starting.  I use this in conjunction with quickstart or run my farm across multiple clients.
     

     

    Any questions or issues feel free to post below and I will respond at some point or hmu on my discord (look at my profile for it).

    o7

    Link to comment
    Share on other sites

    1 hour ago, Nex said:

    BuT YeETuR wHUt aBOuT qICkSTuRT?!?!?!

    I said that this could all be done with quickstart.  For me using multiple clients tho I have to modify 10000 quickstart strings it let's me write shitter management 

    Link to comment
    Share on other sites

    25 minutes ago, depwession said:

    this is cool and all but will it lower ban rate?? 1111111111

    only if you pray to the blood gods.

    Link to comment
    Share on other sites

    • 1 year later...

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.