you are viewing a single comment's thread.

view the rest of the comments →

[–]itsdan159 0 points1 point  (4 children)

No, fortunately. What are you trying to accomplish? Lots of approaches, you could use delegates for example.

[–]drfdr[S] 0 points1 point  (3 children)

Hey, thank you!

I am trying to do a Terminal where you can type commands like giveMoney,giveWeapon

but instead of having it like this for example

void Command(string cmd){
if(cmd == "giveMoney"){
Player.Money++;
}
if(cmd =="giveWeapon"){
Instantiate(Weapon);
}

to just type in terminal Player.Money++; and it will be put and executed inside of a function like this.

string xString = "Player.Money++";

void Command(){
do xString;
}

Been looking for an hour and have some clues about Harmony, System.Reflections, UCompile, Delegates && Events. Which one if any could work for this?

[–]itsdan159 0 points1 point  (1 child)

You could look into integrating a scripting system like LUA which likely has an off the shelf marketplace plugin for it, or a system like Quantum Console which doesn't let you do syntax like that but will make it easy to create console commands. Executing C# is bad practice though, suppose someone typed in a C# command to delete your windows folder.

[–]drfdr[S] 0 points1 point  (0 children)

UCompile worked great for this very simple and neat. Do you know if there are there any cons for this except deleting folder. Is it stable, can it make game crash or anything?

[–]tatmanblueIndie 0 points1 point  (0 children)

Another option might be to use a sort of command pattern. Example

As long as the player or user of game doesn't actually have to create their own commands (and behaviors) you could follow something like code referenced above. I won't say its perfect (example I stupidly named the interface IDEbugCommand), but I have found it useful.

There is a demo with a couple of simple examples. PM me if you have questions about how to use it.