- Home /
Execute code which was written in game
Hello everybody!
Is it possible in any way to write a code, in game, and them execute it? The aim is to allow the player to mod the game.
I program in C# and i have already a little experience with Unity (especially multiplayer games).
Thanks, Nikita
So any user of your application would be allowed to write code, and immediately execute it on top of your code? Seems quite the security risk, what's your goal?
Exactly! I know this is a security risk, but i believe it has to be that way, as i want to allow the player to mod the game.
Answer by $$anonymous$$ · Mar 27, 2013 at 08:12 PM
your looking for possibly a command line library for a console or easy mods, this is no easy task but there is a free library here if you want to get started. It does, however, require a very extensive knowledge of c#. I'm not sure if there is a unityscript( javascript) or boo equivalent. by the way, if your looking to create your own game creator, unity is not the application to do it in.
Thanks for the quick answer! The library looks awesome, though it may not be exactly what i need (or maybe i don't get it), as i'm ai$$anonymous$$g to let the person write a piece of code, which then gets inserted into a script, and then that script gets executed later on. Thanks!
Answer by whydoidoit · Mar 28, 2013 at 08:55 AM
So it depends on your game's platform:
Web player/iOS - you would probably have to build your own scripting language that was interpreted and executed by your game engine. You cannot emit or compile code on these platforms.
PC/Mac - you can probably get System.Reflection.Emit to create .NET IL assemblies at run time from script typed in - by I doubt the C# compiler services are shipped with Unity by default so you'd probably need to build those in a separate assembly using MonoDevelop and then link it into your game.
Console - no idea
It would be pretty hard work - I'd look for a C# open source C# prep/compilation project and try to link with that if you are targeting PC/Mac standalone.
Your answer
