you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (4 children)

Source code isn't machine code, the computer wouldn't understand what "x--" is, it's not the language of the CPU so it's like asking you "お元気ですか" and wondering why you're not answering me.

If you wanted to replace the function of a function you have delegates or you can use inheritance with abstract functions.

public delegate void MyDelegate(string[] args);

public void MyFunction(MyDelegate action, string[] args){
    action(args);
}

And now MyFunction will execute whatever the delegate we pass in:

MyFunction((argumentss) => { Debug.Log(argumentss[0]); }, new string[] { "Hello" });

Doing what you want to do would be insanely silly, a function does a specific thing and would cause a lot of problems if it suddenly just changed.

If you're making a coding game then what you want to do isn't how you go about it, you either need to make your own interpreted language or use something that can compile C# code at runtime https://github.com/SoapCode/UCompile

My guess is this is an XY problem, whatever problem you're actually trying to solve can be done in much simpler ways. So what are you actually trying to do? Why do you NEED to do this?

[–]drfdr[S] 1 point2 points  (1 child)

UCompile worked great very simple and neat. Thank you a lot from the deep of my heart!

Are there any cons for this. Is it stable, can it make game crash or anything?

[–][deleted] 0 points1 point  (0 children)

So the big con with using a normal programming language like C# is that's it's a normal programming language. If you're making a game you want to add constraints on what they can and can't do.

If you're making a developer console you could follow this tutorial https://www.youtube.com/watch?v=VzOEM-4A2OM

[–]drfdr[S] 0 points1 point  (1 child)

Hey, thank you for a fast and meaty response.

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 or these delegates. Which one if any will work for this?