Alek Posted October 18, 2017 Share Posted October 18, 2017 55 minutes ago, thatguycalledrob said: Ah the man himself! Okay okay, I admit that the real reason that I didn't use it was because it didn't work as expected the first time (wouldn't return true when a quest was completed). However, since this whole script is config-based it did make some logical sense to use a different implementation! I guess the API focuses on robustness over most else. Thanks for looking through the code though, it means a lot to have one of the main devs check it! I still want to log which one is causing an error when I have Verbose mode, but you're right in that each if statement calls the function, even if VERBOSE = False. I think I will wrap the whole thing in an if(Verbose){} statement, as to only call them the second time if I am actually wanting an output. Good catch on this, I wouldn't have seen this if I had been looking! Valid, I was worried about this yesterday. I'm fairly new to OSbot & java coding here, so could you, or someone else please help me with a best practice example? I am unsure how often ID's change, and the best implementation for options. are we talking about:https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html ? if so - would you replace my stream:RS2Object Coffin = getObjects().getAll().stream().filter(n -> n.getName().equals("Coffin") && (n.getId() == 15061 || n.getId() == 2145)) With something like:RS2Object Coffin = Optional.ofNullable(getObjects().getAll()).filter(n -> n.getName().equals("Coffin")).orElse("Some default")? Examples would be appreciated! Looks like tomorrows session is just going to be a lot of code cleaning Optional<RS2Object> optional = getObjects().getAll().stream().filter(n -> n.getName().equals("Coffin")).findFirst(); if(optional.isPresent()) { //do things } This is the more "proper" way, however your solution would work. The only static ids which are normally accepted is item ids and config ids. Although config ids have changed in the past they are considered very stable. Definitely replace entity ids with other identifiers, the entity hover debug tool should give you some ideas. As for using configs for checking if a quest is complete or not, that's definitely fine because you know the exact values for your individual quests. You said specifically you are new to Java coding, are you familiar with other languages? Quote Link to comment Share on other sites More sharing options...
thatguycalledrob Posted October 18, 2017 Author Share Posted October 18, 2017 12 hours ago, Alek said: Optional<RS2Object> optional = getObjects().getAll().stream().filter(n -> n.getName().equals("Coffin")).findFirst(); if(optional.isPresent()) { //do things } This is the more "proper" way, however your solution would work. 1 Okay I see, I think this will actually make it easier to solve a bug in the R&J script I found yesterday. Thanks for the example! Out of interest, any idea how to order a stream with multiple values, based on a set of conditions? I was writing a fishing script and I noticed that all bots all move at the same time to the same next spot when one vanishes (probably due to using the . closest API command). I tried to better with a stream it but now it seems to go to the Object with the lowest x+y (coords). Both seem to be easily detectable with some basic pattern recognition on Jagex's side. I wanted to order the stream, and then remove the top n elements of the stream based on a distribution, such that it picks the closes spot with probability p(1), the second with p(2), etc My issue is that I couldn't find a way to do this trivially, either ordering or discarding. I could put the stream (after filtering) into an array, then order, remove, check, etc... but these seem like things that you should be able to do with the inbuilt functionality of Java. 12 hours ago, Alek said: You said specifically you are new to Java coding, are you familiar with other languages? Yessir, I did a placement year last year (might be called a year in industry in the USA) where I basically ended up scripting in VBA 40 hours a week, and I have done a load of C, Maple, R and Matlab over the first half of my degree, although I'm nowhere near as good as I am with VBA. Quote Link to comment Share on other sites More sharing options...
H0rn Posted December 14, 2017 Share Posted December 14, 2017 Super handy, thanks for this Quote Link to comment Share on other sites More sharing options...
labev89390 Posted March 1, 2020 Share Posted March 1, 2020 Hi Thanks for this. I'm learning to write me own scripts and this was usefull for me to learn how do "Switchs" / Cases" TY Quote Link to comment Share on other sites More sharing options...
splatbug Posted March 2, 2020 Share Posted March 2, 2020 Looks good so far, keep it up! Quote Link to comment Share on other sites More sharing options...
JioMy Posted March 2, 2020 Share Posted March 2, 2020 Quite a challenge for first script, very nice. Quote Link to comment Share on other sites More sharing options...
Gabriel Ramuglia Posted January 19, 2022 Share Posted January 19, 2022 The github link doesn't work? Quote Link to comment Share on other sites More sharing options...