To all Java Text-Based game makers!

Hello! I am planning to make a text-based game this year in the Ludum Dare, and I realized how lazy I am…so lazy that I find it hard to keep typing “System.out.println(“walri rock!”)”, so I thought of this:

In the beginning of your main class, make 2 methods, a “say” method and a “take” method, these will work as the cin and count in C++, the say method would be the following:

public static void say(String message){
System.out.println(say);
}

And make the take method the following:

public static void take(String takeTo){
Scanner sc = new Scanner(System.in);
takeTo = sc.nextLine();
}

And TA-DA!!! I am stating now though, that I have NOT tested the take method…Anyhow, you would use the code like this:

//This is a simple intake/output thingy majogger
String input = "";
say("Say something!");
take(input);
say("You said: " + input + "!");

Fell free to use any of this code, and Good Luck to all!!!!!

Comments

pirate-rob
17. Apr 2013 · 11:26 UTC
Wow, I never knew java user input was this easy, rather helpful, thanks!
17. Apr 2013 · 14:03 UTC
The take method will not work – you can’t use Strings as an output in Java because they are immutable. Your sample will always output “You said: !”
bitcrusher
17. Apr 2013 · 14:28 UTC
Your say method won’t work. Try…
bitcrusher
17. Apr 2013 · 14:43 UTC
Have your take method return a String:
LlamaHarmer
17. Apr 2013 · 16:14 UTC
You thought about using the Console?
SuperDisk
17. Apr 2013 · 17:57 UTC
The “take” method won’t work. First, you’re modifying a reference, and you’re not freeing the Scanner sc, causing a memory leak.
EatenAlive3
20. Apr 2013 · 22:15 UTC
For take, try:
Shadow12345
20. Aug 2013 · 23:32 UTC
Hey! what about sysout?