Jump to content
Schepto

Please tell me why I am bad at java.

Recommended Posts

Hello, I am attempting to learn OSBot but I such at Java as it seems like a cancerous mess compared to more noob friendly languages. Plz halp and tell me why I am retarded.

My Main class
 

package Script;

import Quests.Questing;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import Methods.*;

@ScriptManifest(author = "Schepto", name = "Schepto", info = "", version = 1, logo = "")
public final class Main extends Script
{
    private Lib lib = new Lib();                // Library of generic functions and methods.
    private Questing questing = new Questing(); // Takes care of any quest I will ever need to do.

    private void ExchangeContext() { // TBH... All of this is black magic to me and I have no clue why I gotta do this.
        lib.exchangeContext(getBot());
        questing.exchangeContext(getBot());
    }

    @Override
    public final void onStart() { // Happens only once when you first start the bot and after it logs in
        ExchangeContext(); // This must always be first, Prevents NullPointers via black magic.
    }

    @Override
    public final int onLoop() {
        int randomDelay = random(1000, 2000);
        try {
            questing.Execute(); // All individual quests will extend to execute. Those individual quest classes have access to my lib of functions to make writing scripts way faster.
        }
        catch (NullPointerException n) {
            log(n.getCause() + " " + n.getMessage());
        }
        return randomDelay;
    }
}

Placeholder Lib Class with minimal features.
 

package Methods;

import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.MethodProvider;

import java.util.List;

public class Lib extends MethodProvider {

    protected enum ATTACK_STYLES {
        ATTACK(0), STRENGTH(1), DEFENSE(3);
        private final int value;

        ATTACK_STYLES(int value) {
            this.value = value;
        }

        public int get() {
            return value;
        }
    }

    protected void attack(ATTACK_STYLES attack_style, String mob) {
        switch (attack_style.get()) { // TODO: Finish this switch statement and include combat style swapping logic.
            case 0:
                if(configs.get(43) != 0) { // If we are not in the right attack style
                    tabs.open(Tab.ATTACK);
                    // Click the Attack Style
                } else { // our attack style is correct, Go kill some mobs.
                    log("Placeholder");
                    // Attack our mob.
                }
                break;
            case 1:
                break;
            case 3:
                break;
        }
    }

    protected void equipment_check(List<String> equips) {
        equips.forEach(equip -> { // Loop through the list of equipment to check what we need to do.
            EquipmentSlot slot = equipment.getForNameThatContains(equip); // Grab the slot of our current item
            if (!equipment.isWearingItem(slot, equip)) { // If we are not wearing the item
                if (!inventory.contains(equip)) { // if we do not have the item in our inventory
                    withdraw_item(equip); // then get it from the bank
                } else { // if we already have one in our inventory
                    equipment.equip(slot, equip); // then equip it
                }
            }
        });
    }

    private void find_bank() {
        // TODO: Convert to array of banks based on if on member world or not.
        walking.webWalk(Banks.LUMBRIDGE_UPPER); // FIXME : Calculate the closest bank based off the array of banks.
    }

    private NPC find_mob(String mob) {
        try {
            return npcs.closest(mob);
        } catch (NullPointerException n) {
            log("Unable to find a " + mob);
            return null;
        }
    }

    protected void tool_check(List<String> tools) {
        tools.forEach(tool -> { // Loop through the list of tools to check to see if we need to get something.
            if (!inventory.contains(tool)) { // If we do not have the tool in our inventory check the bank for it.
                withdraw_item(tool);
            }
        });
    }

    protected void withdraw_item(String item, Integer amount) {
        try {
            if (!bank.open()) { // if bank is not open
                find_bank(); // then take us to the nearest bank
                RS2Object booth = objects.closest("Bank booth"); // find the closest Bank Booth
                if (booth != null) { // make sure the bank booth is not null
                    booth.interact(); // and then interact with it
                }
            } else { // else if our bank is already open withdraw what we need
                log("Withdrawing " + amount + " " + item);
                bank.withdraw(item, amount);
            }
        } catch (InterruptedException error) {
            log(error);
        }
    }

    protected void withdraw_item(String item) { // overload for withdraw_item so we don't need to type on 1 for amounts if we just need one.
        withdraw_item(item, 1);
    }
}

What I think is a terrible way to extend my Questing classes.... which extend Lib... Tell me why I am retarded here please

 

package Quests;

import Methods.Lib;

public class Questing extends Lib {
    private CooksAssistant cooksAssistant = new CooksAssistant();
    private SheepShearer sheepShearer = new SheepShearer();

    public void Execute() {
        cooksAssistant.Execute();
        sheepShearer.Execute();
    }
}

Cooks Assistant Placeholder here. (Also can I not make these classes a static method like python?... kind of doubt it but if I can make these faster please let me know)

package Quests;

import org.osbot.rs07.api.Quests;

public class CooksAssistant extends Questing {

    public void Execute() {
        log("This is a placeholder for Cooks Assistant Quest.");
        if (!quests.isComplete(Quests.Quest.COOKS_ASSISTANT)) {
            log("We need to finish Cooks Assistant");
            // Logic to finish the quest here
        }
    }
}
Link to comment
Share on other sites

2 hours ago, Alek said:

He thinks null checking is try catching it.

Hey, what does this mean!? Are you saying I think try / catch nullpointer is the same as != null?(wait.... I do think this... (I think i think this??? Check my response to Chris below)

(Probably stupid statement ->) EVEN IF INSIDE THE  onLoop()... So no... its not pointless. Thanks for making me double check tho(didn't double check... dunno why I said this). Go ahead and provide me with a low level example(something I will never understand because fuck math) why I am dumb(I am dumb) even tho thats not the point of High level lang tho.(because the low level guys enable me to be retarded like this) I want to learn Java(be lazy)... not ASM(hard work that I will fail at)

@Alek Not everyone has the low level knowledge you do(because they didn't work as hard and expect to leech from you like me). Stop expecting people to have that(you fucking alien). Your using practicies from Java 6 that are far from relevant now(no authority to say this, just talking out my ass here).
I chose the wrong person to learn from. (This is still true, even post edit) (but not really true, post post edit i was an asshole)

3 hours ago, Chris said:

try {
            return npcs.closest(mob);
        } catch (NullPointerException n) {
            log("Unable to find a " + mob);
            return null;
        }

 

null check ur shit plz


 ExchangeContext();

camelCasing plz

You are correct this is one of the parts I felt was really stupid....(Referring the try return NPC block below... not the thing above) even if im talking out of my ass for most of this this felt like especially extra ass talkery. The point of the second null check was simply to satisfy the compiler even if it "might be dumb" it will still null check and will print me a log instead of crashing your entire OSBOT (Even more dumb IMO) (<-- I still think this is stupid, can you really not prevent making ANY cpu ramp at 100 because of a null pointer?... BULLSHIT) The same reason why I try catch it while you ignore it in your youtube videos @Chris What happens if a noob references a null object? A big, horrendous time consuming crash that you need to alt f4 to end. Woo welcome to Java 8!

Is this not null checked? afaik Its looped inside a Try block that catches null pointers... sorry for not typing if != null like an idiot for every object. (God damn I hope this is right because fuck if(myCancer != null) { DoBullShit(); }

Edited by Schepto
  • :???: 1
Link to comment
Share on other sites

19 minutes ago, Schepto said:

Hey, what does this mean!? You are correct this is one of the parts I felt was really stupid.... even if im talking out of my ass for most of this this felt like especially extra ass talkery. The point of the second null check was simply to satisfy the compiler even if it "might be dumb" it will still null check and will print me a log instead of crashing your entire OSBOT (Even more dumb IMO) 

 

@Alek Not everyone has the low level knowledge you do. Stop expecting people to have that. Your using practicies from Java 6 that are far from relevant now. I chose the wrong person to learn from.

 EVEN IF INSIDE THE  onLoop()... So no... its not pointless. Thanks for making me double check tho. Go ahead and provide me with a low level example why I am dumb even tho thats not the point of High level lang tho. I want to learn Java... not ASM

Is this not null checked? afaik Its looped inside a Try block that catches null pointers...

You're arguing with a dev... If he tells you something isn't right in your code and you don't listen no one can help you.

  • Like 1
Link to comment
Share on other sites

15 minutes ago, d0zza said:

You're arguing with a dev... If he tells you something isn't right in your code and you don't listen no one can help you.

I want to listen to him because he knows more then me. But I don't want to hear BS that I doubt even he believes. If he can not entertain my questions then he is not worth my time. Even if all of you think I am an idiot. Java is not hard.

Edited by Schepto
Link to comment
Share on other sites

40 minutes ago, d0zza said:

Then answer your own questions genius.

Most my questions were answered by myself. I am looking for real input and back and forth with people who understand efficiency. This was not going to be a pretty thread to be begin with as most people who will even be worth talking to this about will probably take this as an insult for whatever reason. I am just waiting for @Alek and or @Chris if he is more then a Alek fanboy to tell me why I am retarded so I can learn from it. Bash me all you want but I would prefer you would do it in the way of my code for this thread. Then you can send me hate in PM that I can ignore.

Edited by Schepto
  • :???: 1
Link to comment
Share on other sites

23 minutes ago, Schepto said:

My questions were answered by myself. I am looking for real input and back and forth with people who understand efficiency. This was not going to be a pretty thread to be begin with I am just waiting for Alek and or Chris if he is more then a Alek fanboy to tell me why I am retarded so I can learn from it. Bash me all you want but I would prefer you would do it in the way of my code for this thread. Then you can send me hate in PM that I can ignore.

Hnnggg I think I have spotted my retardedness... Please halp tear me apart in my "defense" Tho I think I covered the parts I have found where I was wrong.

Edited by Schepto
Link to comment
Share on other sites

1 hour ago, Schepto said:

Hey, what does this mean!? Are you saying I think try / catch nullpointer is the same as != null?(wait.... I do think this... (I think i think this??? Check my response to Chris below)

That is not true. Stop putting your false narrative on me to make your own case. tho....(<-- Cocky asshole)

You are correct this is one of the parts I felt was really stupid.... even if im talking out of my ass for most of this this felt like especially extra ass talkery. The point of the second null check was simply to satisfy the compiler even if it "might be dumb" it will still null check and will print me a log instead of crashing your entire OSBOT (Even more dumb IMO) 

 

@Alek Not everyone has the low level knowledge you do. Stop expecting people to have that. Your using practicies from Java 6 that are far from relevant now. I chose the wrong person to learn from.

 EVEN IF INSIDE THE  onLoop()... So no... its not pointless. Thanks for making me double check tho. Go ahead and provide me with a low level example why I am dumb even tho thats not the point of High level lang tho. I want to learn Java... not ASM

Is this not null checked? afaik Its looped inside a Try block that catches null pointers... sorry for not typing if != null like an idiot for every object.

You may want to change your attitude a bit if you are asking for help from others. Being rude to everyone doesn't make people want to give you advice.

 

"sorry for not typing if != null like an idiot for every object"

It is better practice to check that an instance is != null than surround all your code with a try / catch for a NullPointerException.

You should only really catch exceptions when you can handle them, if you can't handle them, or it doesn't make sense to handle them, they should be deferred to the caller using "throws", for example onLoop() should throw InterruptedException. (Just printing the exception isn't really handling it)

 

"Your using practicies from Java 6 that are far from relevant now. I chose the wrong person to learn from."

Java 6 is still being used for many large software projects, you have to be careful when updating software between major versions as it can easily break, or in this case cause other people's software to break. Also I think saying he is the wrong person to learn from is idiotic, it is clear from this post alone that he knows a lot more about programming than you do, and I can tell you that that the programming language you use, or the version of a programming language you use has no influence on how good a programmer you are.

 

Some more notes about your code:

  1. In Java we use camelCase: findBank() not find_bank()
  2. In Java variable names should start with a lower case letter, class names should start with a capital letter. 
  3. Some of your naming is funky, find_bank() walks to a bank, it doesn't find it?
  4. Methods should return booleans to indicate success, e.g. withdraw_item should return true/false depending on whether it withdrawed an item successfully.
  5. The reason why you need to call exchangeContext() is because the OSBot API has not been initialised on the other classes yet. Classes that extend MethodProvider have variables like bank, inventory, equipment, etc. (that you access with getBank(), getInventory(),...) When you call exchangeContext(Bot bot), the variables will be initialised using the values from the Bot instance, to your new MethodProvider instance.
  6. Lib is a terrible class name, you should rename this to something meaningful. If you saw Lib lib = new Lib(); would you have any idea what that was?! If you can't rename it to something meaningful, then perhaps there is something wrong with your code design, and the functions in that class should belong somewhere else.

 

Edited by Explv
  • Like 4
  • Heart 1
Link to comment
Share on other sites

51 minutes ago, Explv said:

You may want to change your attitude a bit if you are asking for help from others. Being rude to everyone doesn't make people want to give you advice.

 

"sorry for not typing if != null like an idiot for every object"

It is better practice to check that an instance is != null than surround all your code with a try / catch for a NullPointerException.

You should only really catch exceptions when you can handle them, if you can't handle them, or it doesn't make sense to handle them, they should be deferred to the caller using "throws", for example onLoop() should throw InterruptedException. (Just printing the exception isn't really handling it)

 

"Your using practicies from Java 6 that are far from relevant now. I chose the wrong person to learn from."

Java 6 is still being used for many large software projects, you have to be careful when updating software between major versions as it can easily break, or in this case cause other people's software to break. Also I think saying he is the wrong person to learn from is idiotic, it is clear from this post alone that he knows a lot more about programming than you do, and I can tell you that that the programming language you use, or the version of a programming language you use has no influence on how good a programmer you are.

 

Some more notes about your code:

  1. In Java we use camelCase: findBank() not find_bank()
  2. In Java variable names should start with a lower case letter, class names should start with a capital letter. 
  3. Some of your naming is funky, find_bank() walks to a bank, it doesn't find it?
  4. Methods should return booleans to indicate success, e.g. withdraw_item should return true/false depending on whether it withdrawed an item successfully.
  5. The reason why you need to call exchangeContext() is because the OSBot API has not been initialised on the other classes yet. Classes that extend MethodProvider have variables like bank, inventory, equipment, etc. (that you access with getBank(), getInventory(),...) When you call exchangeContext(Bot bot), the variables will be initialised using the values from the Bot instance, to your new MethodProvider instance.

 

EDIT got the difference between them now. 

also thank you for serving me. Sorry I was disrespectful this is a good community.

sorry that I was rude but I firmly disagree that being rude is a bad path. It may make people dislike me but it gets me talking to the people who know the most the fastest. I am not looking for someone to pat me on the back. It is easier to ask for forgiveness then for permission.

EDIT gonna keep using snake_case for personal projects. I would not bother working on a java project anyways. (<-- not trying to say im too good for java infact java is just too old from what im use to and legacy code sucks and pays dog shit(at least compared to the skill it takes.. you guys are way smarter and get way less and I don't understand the masochism... ill stick to tensorflow and matlib for now)).

Edited by Schepto
Link to comment
Share on other sites

 

1 hour ago, Schepto said:

you guys are way smarter and get way less and I don't understand the masochism... ill stick to tensorflow and matlib for now)).


Stop pulling stuff out of your ass. Java is one of the highest paid languages, no one is paying you shit for tensorflow and matlib???? :???:

Also wtf is the point of this thread? Don't post a thread in scripting help asking why your code is bad, and then go on a tangent about how Java sucks and tensor flow and matlib is superior :???:

Why are you even here?

Edited by Explv
  • Heart 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...