Jump to content

dialogue box help


iTz EcLiPsE

Recommended Posts

if (widgets.getAll().stream().filter(w -> w.isVisible() && w.hasAction("Cook All")).count > 0) 
widgets.getAll().stream().filter(w -> w.isVisible() && w.hasAction("Cook All")).findFirst().get().interact("Cook All");

The above code will select the option "Cook All" on any widget if the widget is visible. Make sure the action is spelled correctly with uppercase C and A as I don't know if it's supposed to be uppercase or lowercase A.

Link to comment
Share on other sites

if (widgets.getAll().stream().filter(w -> w.isVisible() && w.hasAction("Cook All")).count > 0) 
widgets.getAll().stream().filter(w -> w.isVisible() && w.hasAction("Cook All")).findFirst().get().interact("Cook All");

The above code will select the option "Cook All" on any widget if the widget is visible. Make sure the action is spelled correctly with uppercase C and A as I don't know if it's supposed to be uppercase or lowercase A.

 

 

That's inefficient as hell. Why aren't you caching the Widget from the first query and reusing it?

Link to comment
Share on other sites

That's inefficient as hell. Why aren't you caching the Widget from the first query and reusing it?

Filtering streams is actually very fast. You may cache the widget if you want but then you will continously null check it and verify its visibility which you pretty much do with the above code.

 

As a general rule when writing code, you first make it work and in future iterations you begin optimising it.

Link to comment
Share on other sites

Filtering streams is actually very fast. You may cache the widget if you want but then you will continously null check it and verify its visibility which you pretty much do with the above code.

 

As a general rule when writing code, you first make it work and in future iterations you begin optimising it.

 

You're talking to the wrong person about "general rules of writing code". It doesn't matter if it's "fast", you're sacrificing readability & performance for absolutely no reason. You shouldn't write shit code when another (better) solution is so blatantly obvious. Not only is it shorter (and therefore more readable), but it performs significantly faster.

 

Also, your code has a race condition. If the Widget state changes in between those 2 calls, you're going to get an NPE depending on the API implementation.

 

tl;dr stop giving shit, buggy code to beginners

Edited by demmonic
  • Like 2
Link to comment
Share on other sites

You're talking to the wrong person about "general rules of writing code". It doesn't matter if it's "fast", you're sacrificing readability & performance for absolutely no reason. You shouldn't write shit code when another (better) solution is so blatantly obvious. Not only is it shorter (and therefore more readable), but it performs significantly faster.

 

Also, your code has a race condition. If the Widget state changes in between those 2 calls, you're going to get an NPE depending on the API implementation.

 

tl;dr stop giving shit, buggy code to beginners

 

lol i didnt understand half of what u said lmao i dont know how to do much for scripting so im sure most of my code is broken or insufficient anyway just trying to make something actually work for learning until i understand alot more so i can actually release scripts any advise or maybe tutorials u recommend are appreciated.. :) 

Link to comment
Share on other sites

lol i didnt understand half of what u said lmao i dont know how to do much for scripting so im sure most of my code is broken or insufficient anyway just trying to make something actually work for learning until i understand alot more so i can actually release scripts any advise or maybe tutorials u recommend are appreciated.. smile.png

 

I don't really care for tutorials as you can't really encompass a whole language in something that small. I would recommend a book to get an overview of the language, and to act as a reference when you can't figure something out (google helps too.) Other than that, practice makes perfect.

 

The sole reason I don't like people suggesting stuff like that to a beginner is because it's easy to form habits when you don't know any better, but it's generally hard to change them.

 

Anyways, you can always PM me your Skype if you want real time help. I'd be happy to help/give advice in my free time.

Link to comment
Share on other sites

I don't really care for tutorials as you can't really encompass a whole language in something that small. I would recommend a book to get an overview of the language, and to act as a reference when you can't figure something out (google helps too.) Other than that, practice makes perfect.

 

The sole reason I don't like people suggesting stuff like that to a beginner is because it's easy to form habits when you don't know any better, but it's generally hard to change them.

 

Anyways, you can always PM me your Skype if you want real time help. I'd be happy to help/give advice in my free time.

 

that sounds awesome thank you any particular book u recommend??i think alot of my issues when it comes to writing code (besides being new to it) is i dont know the commands and what all the commands mean and do

Link to comment
Share on other sites

You're talking to the wrong person about "general rules of writing code". It doesn't matter if it's "fast", you're sacrificing readability & performance for absolutely no reason. You shouldn't write shit code when another (better) solution is so blatantly obvious. Not only is it shorter (and therefore more readable), but it performs significantly faster.

 

Also, your code has a race condition. If the Widget state changes in between those 2 calls, you're going to get an NPE depending on the API implementation.

 

tl;dr stop giving shit, buggy code to beginners

I highly doubt flaming me for trying to help him solve his problem is going to get you anywhere. But if you do insist on trying to prove I'm wrong, you aren't going to get anywhere because simply by saying that my condition is wrong and the widget state can change between those 2 calls prove you don't know anything about scripting, the OSBot API or programming in general.

 

Some reputable scripters on this site have public APIs they implemented in their scripts which you might want to take a look at before accusing my code of being "shit", you definately have a lot to learn from that and you might be surprised to find solutions very similar to the one I presented above.

 

TL;DR: Find something constructive to do with your time.

Link to comment
Share on other sites

I highly doubt flaming me for trying to help him solve his problem is going to get you anywhere. 

 

...

 

TL;DR: Find something constructive to do with your time.

I'm not flaming in any way. Yes, I called the tiny snippet of code you posted buggy, and "shit". That is not me flaming you in any way. If you want to get all defensive and post bullshit insults towards me as a person (you've done this several times now, acting like I'm an idiot who doesn't know how to program), then go for it, pal. You're the one that needs to find something constructive to do with your time.

 

But if you do insist on trying to prove I'm wrong, you aren't going to get anywhere because simply by saying that my condition is wrong and the widget state can change between those 2 calls prove you don't know anything about scripting,

Prove it then buddy. I'm a bot developer unlike you, and unless the scripting is handled on the game engine's thread (it's not.) You have a race condition!

 

Some reputable scripters on this site have public APIs they implemented in their scripts which you might want to take a look at before accusing my code of being "shit", you definately have a lot to learn from that and you might be surprised to find solutions very similar to the one I presented above.

Ok? So you're going to defend yourself by saying that other bad developers are doing what you're doing? Hooray for confirmation bias! Also, more passive aggressive insults via your big ego! Yes yes, you know everything, and I know nothing.

 

Please don't even bother replying to me, I'm ending this here. You're too stupid to listen to anything I have to say. You throw personal insults everywhere, go off topic, and are extremely stubborn.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...