Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resolved Waiting on ChatDialog

Joined
Jan 31, 2017
Messages
121
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.
 
Joined
Jan 31, 2017
Messages
121
Code:
if(chatdialogue != null) {
// do stuff
} else {
// interact with gameobject
}
?
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?
 
Joined
Jun 9, 2015
Messages
3,716
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?
Do you want to wait until a dialog is open? What kind of dialog are we talking about here? Screenshot?
 
Joined
Jan 31, 2017
Messages
121
Do you want to wait until a dialog is open? What kind of dialog are we talking about here? Screenshot?
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
 
Last edited:
Joined
Jun 9, 2015
Messages
3,716
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
Code:
if(ChatDialog.getOption("Which tool would you like?") != null) {
// Chatdialog is there
} else {
// Interact with gameobject
}
 
Joined
Jan 31, 2017
Messages
121
Code:
if(ChatDialog.getOption("Which tool would you like?") != null) {
// Chatdialog is there
} else {
// Interact with gameobject
}

I've tried the same with
Code:
ChatDialog.getText();
, but that throws Nullpointer as well. But
Code:
ChatDialog.getOption("Trowel") != null
works, Thanks man!
 
Joined
Jun 9, 2015
Messages
3,716
I've tried the same with
Code:
ChatDialog.getText();
, but that throws Nullpointer as well. But
Code:
ChatDialog.getOption("Trowel") != null
works, Thanks man!
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.
 
Joined
Jan 31, 2017
Messages
121
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.
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)?
 
Joined
Jun 9, 2015
Messages
3,716
When calling:
Code:
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:
if(ChatDialog.getText() != null) {
It will check if the contained text is not null. If it's not null you can do:
Code:
ChatDialog.getText();

Full code:
Code:
if(ChatDialog.getText() != null) {
// There is text!
ChatDialog.getText();
} else {
// There is no text / text is null
}
 
Joined
Jan 31, 2017
Messages
121
When calling:
Code:
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:
if(ChatDialog.getText() != null) {
It will check if the contained text is not null. If it's not null you can do:
Code:
ChatDialog.getText();

Full code:
Code:
if(ChatDialog.getText() != null) {
// There is text!
ChatDialog.getText();
} else {
// There is no text / text is null
}
Thanks, cleared up a lot!

Resolved/Answered.
 
Joined
Jun 8, 2017
Messages
184
if you want a more solid way to check if anything is covering the chatbox:

Code:
        String s = ChatDialog.getText();
        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)
 
Top