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

Resolved Waiting on ChatDialog

Discussion in 'Developer Support' started by Aaron Priest, Apr 9, 2017.

  1. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    After interacting with a GameObject, I need to wait for the ChatDialog to turn up. Any smart ways of doing that out there? Interacting with ChatDialog before there is one throws NullPointerException and I can't find anything that listens for such events.
    The duration of the delay is dependent on the distance of the player to the GameObject that he interacts with.

     
  2. Best Answer:
    Post #10 by Jhinn, Apr 9, 2017
  3. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    Code (Text):
    1. if(chatdialogue != null) {
    2. // do stuff
    3. } else {
    4. // interact with gameobject
    5. }
    6.  
    ?
     
  4. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    I've only accessed ChatDialog via the static modifier. Maybe I had a wrong understanding about its concept. How would you initialize the instance chatdialog of type ChatDialog? Does the default constructer retrieve any open ChatDialogs?
     
  5. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    Do you want to wait until a dialog is open? What kind of dialog are we talking about here? Screenshot?
     
  6. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    Exactly. After Interacting with a GameObject that contains tools, I need to wait until the dialog is open before interacting with its options. The dialog itself is not more than the text: "Wich tool would you like?" and 4 options to choose from.

    Imgur: The most awesome images on the Internet
     
    #5 Aaron Priest, Apr 9, 2017
    Last edited: Apr 9, 2017
  7. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    Code (Text):
    1. if(ChatDialog.getOption("Which tool would you like?") != null) {
    2. // Chatdialog is there
    3. } else {
    4. // Interact with gameobject
    5. }
     
    Aaron Priest likes this.
  8. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    I've tried the same with
    Code (Text):
    1. ChatDialog.getText();
    , but that throws Nullpointer as well. But
    Code (Text):
    1. ChatDialog.getOption("Trowel") != null
    works, Thanks man!
     
  9. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    If there is no dialog, and you try to search for ChatDialog.getText(), it will return null -> Resulting in that error.
    Glad I could help.
     
  10. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    If you don't mind me asking, is the reason because your way works and mine didn't the fact that I tried to equal check a string that is null (which is now that I think about it so obvious), and you check if the object is null (which obviously works)?
     
  11. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    When calling:
    Code (Text):
    1. ChatDialog.getText()
    You essentially asking for the text that the ChatDialog contains, but if there is no dialog, how can there be any text? This results in an instant NPE.
    If you call:
    Code (Text):
    1. if(ChatDialog.getText() != null) {
    It will check if the contained text is not null. If it's not null you can do:
    Code (Text):
    1. ChatDialog.getText();
    Full code:
    Code (Text):
    1. if(ChatDialog.getText() != null) {
    2. // There is text!
    3. ChatDialog.getText();
    4. } else {
    5. // There is no text / text is null
    6. }
     
    Aaron Priest likes this.
  12. Aaron Priest

    Joined:
    Jan 31, 2017
    Messages:
    121
    Likes Received:
    30
    Thanks, cleared up a lot!

    Resolved/Answered.
     
  13. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,647
    Likes Received:
    1,337
    No problem. Good luck. For additional questions, you can always join the Developer Slack team. Be aware: We do not spoonfeed in there ;)
     
  14. S h e e n a

    S h e e n a Learner

    Joined:
    Jun 10, 2017
    Messages:
    37
    Likes Received:
    9
    How can I join the Slack Team?
     
  15. Negrita

    Joined:
    Jan 28, 2017
    Messages:
    491
    Likes Received:
    183
  16. SilenceP44

    Joined:
    Jun 8, 2017
    Messages:
    184
    Likes Received:
    87
    if you want a more solid way to check if anything is covering the chatbox:

    Code (Text):
    1.         String s = ChatDialog.getText();
    2.         return s != null && s.startsWith(PlayerUtil.getPlayer().getName() + ": ");
    returns true if nothing is covering the chatbox, don't think there is a single edge case (yet)
     

Share This Page

Loading...