thanks for getting back to me so quickly! You're right, I should have provided more information.
I am trying myself at an ingame terminal and started with a rough implementation:
function Terminal(runtime) {
this.commandList;
this.terminalInput = runtime.objects.tTerminalInput.getFirstInstance();
this.terminalText = runtime.objects.tTerminalText.getFirstInstance();
this.selectedObject;
this.typeTime = 0.5;
}
Terminal.prototype.openTerminal = function (runtime, object) {
// save the selected object
this.selectedObject = object[0];
// save the available commands of the selected object
this.commandList = this.selectedObject.instVars.commandList.split(',');
this.terminalText.typewriterText("Hacking " + this.selectedObject.objectType.name, this.typeTime);
// show terminal UI
runtime.layout.getLayer("Terminal").isVisible = 1;
player.behaviors.Platform.isEnabled = 0;
player.instVars.terminalIsOpen = 1;
};
Terminal.prototype.closeTerminal = function (runtime) {
// hide terminal UI
runtime.layout.getLayer("Terminal").isVisible = 0;
player.behaviors.Platform.isEnabled = 1;
player.instVars.terminalIsOpen = 0;
};
// get the cmd input of the player
Terminal.prototype.getTextInput = function(runtime){
terminal.runCommanIfExists(this.terminalInput.text, runtime);
console.log("input: " + this.terminalInput.text);
this.terminalInput.text = "";
}
// check if entered command exists for the selected object
Terminal.prototype.runCommanIfExists = function(input, runtime){
this.commandList.forEach(function(command) {
if(command == input){
terminal.runFunction(input, runtime);
};
});
}
Terminal.prototype.runFunction = function(command, runtime){
console.log("command: " + command);
switch (command) {
case "help":
this.fHelp();
break;
case "exit":
this.fExit(runtime);
break;
case "exit -h":
this.fExitH();
break;
case "sleep":
this.fSleep();
break;
default:
console.log("default");
//this.fUnknownCommand();
}
}
//
// TERMINAL FUNCTIONS
//
Terminal.prototype.fHelp = function(){
var string = "This object supports the following functions. Enter <command> -h to get more information.";
this.commandList.forEach(function(command) {
string += "\n- " + command;
});
this.terminalText.typewriterText(string, this.typeTime);
}
Terminal.prototype.fExit = function(runtime){
this.closeTerminal(runtime);
}
Terminal.prototype.fExitH = function(){
this.terminalText.typewriterText("exit - close the terminal", this.typeTime);
}
Terminal.prototype.fUnknownCommand = function(){
this.terminalText.typewriterText("Not a valid command, try help.", this.typeTime);
}
Terminal.prototype.fSleep = function(){
console.log("sleeping nowwww");
}
The player can enter commands in a text input field and when they hit enter their command is parsed.
While writing this text I am realizing that only commands provided by the selected object will work. And my test object does not provide other commands than help and exit in its commandList.
Wow.. so much for code blindness. But writing this post helped me find it, so thank you very much! Especially for the fast response. I will mark this as solved.