Nifty console input

I want to grabb the text from the nifty console, i use a key listener on enter and then use the following code to grabb the input.



console = nifty.getCurrentScreen().findNiftyControl(“console”, Console.class);

String consoleInput = console.getTextField().getText();



the problem is, nifti clears the TextField on enter so i cant get the input.



Is there a simple way just to get the input from the console?



any help is greatly appreciated.

1 Like

http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Standard_Controls_Console



You should use ConsoleCommands rather than your own key listener.

abies said:
http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Standard_Controls_Console

You should use ConsoleCommands rather than your own key listener.


Well im not interested in console commands i mainly intend to use it for chat, so i much rather just want to get the Strings. if it's somehow possible.

The link that abies posted solves your problem. Maybe read it? :slight_smile:



When the console submits a new line of text an event is generated by Nifty. You just need to subscribe to this event http://nifty-gui.sourceforge.net/projects/1.3/nifty-default-controls/apidocs/de/lessvoid/nifty/controls/ConsoleExecuteCommandEvent.html It is just called commandEvent. There is no command translation performed. You get the whole line of text with that event too.

void256 said:
The link that abies posted solves your problem. Maybe read it? :)

When the console submits a new line of text an event is generated by Nifty. You just need to subscribe to this event http://nifty-gui.sourceforge.net/projects/1.3/nifty-default-controls/apidocs/de/lessvoid/nifty/controls/ConsoleExecuteCommandEvent.html It is just called commandEvent. There is no command translation performed. You get the whole line of text with that event too.


i tryed

import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.controls.ConsoleExecuteCommandEvent;

public class Main extends SimpleApplication implements ScreenController
{
.
.
. my other code :P
.
.

@NiftyEventSubscriber(id="console")
public void onConsoleExecuteCommandEvent(final String id, final ConsoleExecuteCommandEvent cEvent )
{
String consoleInput = cEvent.getCommandLine();
}
}

the function doesnt get called, why?

no idea. it looks right. I’ve just tested it here and it works very well. is that screencontroller linked to the xml in some unusual way? whats the xml looking or do you use the java builder stuff?



if all else fails, please take the time and try this in some MINIMAL test project - with all of your other code removed :stuck_out_tongue: - and make that available for me to take a look. there must be something missing somewhere. you’re using the latest nifty I suppose?

1 Like

I did a minimal project and it worked like a charm. After that I started new project an re-did everything and now it works, ty for all the help.