Developer Console - GameDevWeek/CodeBase GitHub Wiki
The Developer Console is an Ingame Console, through which you can view (and filter) Logs, as well as enter commands and change variables.
- To toggle the console ingame, press F12.
- Enter
listcvars
to list all available console variables (cvars)- More options are available to filter the results ( enter
help listcvars
)
- More options are available to filter the results ( enter
- Enter
listcmds
to list all commands- More options are available to filter the results ( enter
help listcmds
)
- More options are available to filter the results ( enter
- Enter
help <command or cvar>
to get information on how to use a command or cvar. - On cvars you can also just enter the cvar name without a value to get additional information.
- To use autocompletion, Enter at least one character and press tab.
- Press tab again to cycle through options (if there are multiple)
- Autocompletion is available for commands, cvars and their parameters/values.
- To use Autocompletion on a parameter or cvar value, enter a space between the command/cvar and then press tab.
- Use mousewheel to scroll the log, or drag the log with your mouse/finger.
- Use up/down arrows to go through the history of your latest commands.
- press ctrl+tab to print usage for the entered command
- Press Page-Up or Page-Down to scroll to the top or the bottom of the log.
Any log you write with SL4J will be visible in this console.
- You can use log_filter to change what log levels will be hidden (use space to separate different log levels).
- log_height sets the percentage of the window height the console should use.
ConsoleCmd(String name, int flags, String description, [int minArguments])
-
name
is the command you enter in the console -
description
is shown when using the help command. -
flags
can be ignored for now (pass 0) -
minArguments
is optional, and the minimum arguments that need to be passed before this command will be executed
ConsoleCmd myCommand = new ConsoleCmd("myCommand", 0, "Do some stuff") {
@Override
public void execute(List<String> args) {
// This will be executed on enter.
}
};
console.register(myCommand); // use unregister if you want to remove a command
ConsoleCmd dostuff = new ConsoleCmd("dostuff", 0, "Do stuff with parameters", 1) { // 1 = minimal arguments
@Override
public void showUsage() {
showUsage("<required param> [optional param]"); // will print as: ""Usage: dostuff <required param> [optional param]"
}
@Override
public void execute(List<String> args) {
// This will only be called if at least minimal arguments have been entered.
// Args.get(0) == command name
String param1 = args.get(1);
if (args.size() > 2) {
String param2 = args.get(2);
}
}
};
If you want to support autocompletion for the first parameter, you'll need to override this method as well:
@Override
public void complete(String prefix, List<String> results) {
// prefix contains the word to be completed.
final String lowerPrefix = prefix.toLowerCase();
for (String value: values) {
if (value.toLowerCase().startsWith(lowerPrefix)) {
results.add(value);
}
}
}
There are different cvar types available:
-
CVarBool(String name, boolean defaultValue, int flags, String description)
- Can be true or false
-
CVarInt(String name, int defaultValue, int min, int max, int flags, String description)
- Can be any integer between min and max (inclusive)
-
CVarFloat(String name, float defaultValue, float min, float max, int flags, String description)
- Can be any float between min and max (inclusive)
-
CVarEnum(String name, T defaultValue, Class<T> clazz, int flags, String description)
- Can be any of the enums type.
-
CVarString(String name, String defaultValue, int flags, String description)
- Can be anything that fits in a string.
-
name
is the command you enter in the console -
description
is shown when using the help command. -
clazz
is the enum class (for exampleMyEnum.class
) -
flags
can be ignored for now (pass 0)
CVarEnum<SoundEmitter.Mode> emitterMode = new CVarEnum("snd_mode", SoundEmitter.Mode.STEREO, SoundEmitter.Mode.class, 0, "sound mode");
console.register(emitterMode); // use unregister if you want to remove a cvar
// If you need to react to changes of the variable, add a listener:
emitterMode.addListener((CVar cvar)-> {
//...
SoundEmitter.setListenerPosition(x, y, z, emitterMode.get());
});
The Base-Code does not need the Ingame-Console, so you could easily write a different interface for it using System.out and System.in or even a UI Library like Swing/JavaFX. This could be handy for dedicated servers.