1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Arrays/Lists with GameObjects

Discussion in 'Developer Support' started by Shwoopy, Dec 5, 2020.

  1. Shwoopy

    Joined:
    Dec 4, 2020
    Messages:
    5
    Likes Received:
    3
    Hey folks. I'm new around here and trying my hand at putting together some bots. Not entirely new to scripting but this is getting me.

    Basically, I am trying to get all reachable iron ores from a position (there should be 3), and add them into an array/list. Here is currently what the section looks like:

    Code (Text):
    1. public void execute() {
    2.         OreMuncher.rocks = GameObjects.newQuery().reachableFrom(OreMuncher.getOreLocation()).ids(11365).actions("Mine").results().asList();
    3.         if(OreMuncher.rocks.size() > 0) logText("Rocks found");
    4.         if(OreMuncher.rocks.size() > 0 && OreMuncher.getPlayer() != null && Distance.between(OreMuncher.getOreLocation(), OreMuncher.getPlayer()) < 1){
    5.             logText("Mining iron");
    6.             switch(OreMuncher.getRockSelect()){
    7.                 case 0: {
    8.                     OreMuncher.rockSelect++;
    9.                     OreMuncher.rocks.get(OreMuncher.rockSelect).interact("Mine");
    10.                 }
    11.                 case 1: {
    12.                     OreMuncher.rockSelect++;
    13.                     OreMuncher.rocks.get(OreMuncher.rockSelect).interact("Mine");
    14.                 }
    15.                 case 2: {
    16.                     OreMuncher.rockSelect = 0;
    17.                     OreMuncher.rocks.get(OreMuncher.rockSelect).interact("Mine");
    18.                 }
    19.             }
    20.             Execution.delayUntil(()->OreMuncher.getPlayer().getAnimationId() != -1, 5000);
    21.         }
    22.         else if(OreMuncher.getPlayer() != null && Distance.between(OreMuncher.getOreLocation(), OreMuncher.getPlayer()) > 1) {
    23.                 logText("Moving to mining location");
    24.                 Path p = RegionPath.buildTo(OreMuncher.getOreLocation());
    25.                 if(p != null)
    26.                     p.step();
    27.         }
    28.         else if(OreMuncher.rocks.size() == 3 && !OreMuncher.rocks.get(OreMuncher.rockSelect).isVisible())
    29.             Camera.turnTo(OreMuncher.rocks.get(OreMuncher.rockSelect));
    30.         else logText("No rocks found.");
    31.     }
    I am using rockSelect to keep track of which rock the player is currently mining. OreMuncher.rocks is the list I created in the main class with
    Code (Text):
    1. public static List<GameObject> rocks = new ArrayList<>();
    When in-game, absolutely nothing happens. All other parts of my script bot work; world switching, retrieving the pickaxe, dropping, I'm just struggling with getting these stupid rocks into a list.

    Thanks heaps folks! Let me know if you need anything more from me :)
     
  2. bia10

    Joined:
    Feb 24, 2020
    Messages:
    33
    Likes Received:
    4
    i quite don't get why do you need to overcomplicate things at start, scripts bots naturally get overcomplicated as time passes begin as simple as you can

    why exactly do you need to know which rock your mining?

    why do you need check for reachability? is there some unreachable rock from position OreMuncher.getOreLocation()?

    do you need to control exactly which rock out of the 3 your mining? or cannot you just return the .nearest one to OreMuncher.getOreLocation()?

    what kind of reasons have led you to believe that using simple rock decision by color substitution is not enough for this task?
     
  3. Shwoopy

    Joined:
    Dec 4, 2020
    Messages:
    5
    Likes Received:
    3
    The idea is that I wanted to keep track of which rock I am mining so that I can hover over the next one, for example, and allow me to keep mining in a pattern instead of randomizing it. I am trying to create a powermining bot in which I stand in one location between three ore deposits, so using reachability seemed like the easiest method to gather the three rocks Objects. Just getting the nearest one would not work either as it would just be grabbing one rock consistently, am I wrong?
     
  4. bia10

    Joined:
    Feb 24, 2020
    Messages:
    33
    Likes Received:
    4
    Well the rock has certain states like depleted not depleted upon the change of the state the color of rock changes. Therefore if the rock is depleted color substitution disqualifies this rock from the query for gameObject.

    quite frankly, if there is no need for rock selection pattern or order in which rocks are mined, then just handle them 1 by 1
    if your mining iron why this doesn't suffice?

    Code (Text):
    1.  
    2. GameObject ironRocks = GameObjects.newQuery().colorSubstitutions(new Color(48,48,48), newColor(32,17,14)).results().nearestTo(OreMuncher.getOreLocation());
    3.  
     
    Shwoopy likes this.
  5. Shwoopy

    Joined:
    Dec 4, 2020
    Messages:
    5
    Likes Received:
    3
    That sounds like it could be a solution - I was just struggling to figure out how to make it target the three rocks closest to one point without running across the quarry, I thought an array with reachable objects would be an easy solution but your solution seems much better.

    Thank you my friend, I'll give it a go!
     
  6. bia10

    Joined:
    Feb 24, 2020
    Messages:
    33
    Likes Received:
    4
    runemate development is very confusing, and you seem to fail to appreciate the subtle devilry between something being reachable/pathable/navigable these things are all different!
    • also i would switch to TreeBot implementation
    • the null check for player works only if your not relogging then it may still return null once relogged refreshment of getLocal player may be needed
    • the local pathing will often return null not very reliable
     
    Shwoopy likes this.
  7. Shwoopy

    Joined:
    Dec 4, 2020
    Messages:
    5
    Likes Received:
    3
    I have seen a lot of information saying that WebPath is broken, but then at the same time I see some people that sound like they may have used it and have it work. Does WebPath work better then local pathing still at this point? If so, I'll have to go that a go tomorrow.

    Really appreciate the information, thank you!
     
  8. bia10

    Joined:
    Feb 24, 2020
    Messages:
    33
    Likes Received:
    4
    the situation is far more messy then that....

    yes web is broken to most places
    local pathing sometimes works, but even if it does it still performs sluggish, there's some weird micro delay on each step taken

    so the only rescue so far seem to be

    Custom Web Maker
     
  9. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,114
    Likes Received:
    1,371
    @Shwoopy I just got home from a long day so my brain isn't working at full capacity, but one quick thing I noticed is that you should really avoid using static variables of any kind in your bots (unless they're constants, I guess). By my understanding, static variables have a weird interaction if more than one bot is being run on the same runemate instance; If more than one bot of the same kind is being run on runemate, with static variables, I think the static variables are shared/interact in a non-deterministic way since both bots are trying to access the same variable.

    Besides that it seems like Bia already covered most of the feedback: you can simplify a lot of the logic using a more precise query, you should nullcheck more stuff (especially Players.getLocal(), but a lot of things queried from runemate can return null unexpectedly, like Inventory.getItems(), object queries etc. I just assume all queries may be null and nullcheck/cache them as needed), colorSubs is helpful for mining. Also if you want to find the rocks directly adjacent to the player, what I personally do is have a function that takes in the player's current position and returns a "cross" area that derived from the current player area, and use this "cross" area in the GameObject query.

    And of course if this is empty then search for 3 rocks nearby and have your pathing logic to get there (for such a small area, bresenhampath or regionpath should be fine, but custom webs are an option for more complex pathing).
     
    Shwoopy likes this.
  10. Shwoopy

    Joined:
    Dec 4, 2020
    Messages:
    5
    Likes Received:
    3
    Thank you so much for the reply, Cuppa >:) Ironically, your AIO miner was partially what inspired me to give this a shot myself.
    I have found out the hard way about everything returning null; I've gone through and added many null checks and learned how to combat that thankfully.

    Really though, lots of great information here - thank you everybody! Learning lots today already; proud of my progress.
    Going to go and read up on static variables and work on getting them out of my script bot.

    Also will be working on converting over to a TreeBot instead of TaskBot.
    Thanks guys!
    --- Double Post Merged, Dec 9, 2020, Original Post Date: Dec 6, 2020 ---
    Wanted to say I really appreciate your guys' support. You really inspired me to continue and I am extremely proud of the progress I have made and what I have learned when it comes to RuneMate's API in the last few days, and especially you, Cuppa, seeing how well your AIO miner works. Me being the poor sod I am, I wanted to go ahead and try making my own. I'm getting there.

    I've become familiar with JavaFX and Scene Builder and created beautiful embedded UI. I've got the custom web pathing working (also if there is anybody else out there looking for an extremely handy world map that generates coordinates and areas: bless). I've also converted to TreeBot and I agree, it is much more pleasant to work with.

    Hopefully I'll be able to actually get some bots on the store soon. Rome wasn't built in a day!
    ;)

    Thanks dudes.

    Side node, the 2 account 15 minute limit thing: very annoying when I'm constantly in and out testing :p
    My fault for closing improperly I think but dang

    [​IMG]

    Super pumped and excited to see where my journey takes me.
     
    #10 Shwoopy, Dec 9, 2020
    Last edited: Dec 9, 2020
    bia10 and CuppaJava like this.

Share This Page

Loading...