Allowing Players To Code INSIDE your games?

Hi, i'm just wondering if it's possible to allow players to code inside your games, for example, say you made a game like second life, the reason why second life is still here today is because it is run by the players, they can build and code with Linden Lab's special programming language.

Can someone tell me if this is possible?

Example (Java) Someone codes a box to move away when approached.

Example (Java) Someone codes a box to change colors.

Thanks for reading.

Either you can allow C# and compile the code on the fly or you can use some scripting language such as lua, angelscript, python or make your own (this book teaches you to make a full scriptable language). Scripts would be run by some interpreter or virtual machine, usually provided as a library for the different languages. To create a virtual machine is pretty trivial, even making an assembler is quite easy. The hard part if you want to create your own language is the high level language since you have to keep quite a lot of things in mind.

You can use eval() in Javascript, but that leaves really huge security holes open, so you'd better not. Better to implement your own scripting language.

lua is a small, free, open source scripting language that has frequently been used in game engines. This project seeks to integrate it with .NET, which could be helpful for use from Unity.

I was able to make Lua run inside Unity using LuaInterface 1.5.3.

With this, you can let players add lua scripts as code. The hard part is having to expose your game's innards to Lua so players can modify your game to the extent that you want.

See forum post here:

Ok, after some fiddling, the good news, I got it working. The bad news, not with the latest version of LuaInterface, but with version 1.5.3, the last 1.x version.

Versions I've tried and failed to make it work: 2.0.1, 2.0.3

Versions I've tried and made it work: 1.2, 1.3.0, 1.4.0*, 1.5.3

*: the lua dlls supplied in 1.4.0 were not being recognized, so I simply used the lua dlls from 1.3.0 to make it work, but the LuaInterface code version 1.4.0 works

To make it work in the Unity Editor, the main lua dll plus an additional luanet.dll has to be somewhere Unity can find. In Windows, I copied them to the folder where Unity.exe resides. Additionally, to make it work on standalone release builds, those two dlls have to be somewhere your .exe file can find. The easiest is to copy them to the same folder where the .exe file is. I assume for Mac standalones you have to do something similar.

The downloadable 1.x versions of LuaInterface also come with its source code bundled along, so you can use the source code version of LuaInterface if you don't want it as a dll.


I'm in the process of turning this into a package for the asset store, watch out for it!

UPDATE: Here's a link:

That is an incredible idea, although I have no idea about how to do that, I would imagine it to be very difficult. If you wanted to have full control of unity type programs, you would have to make it so that the user can go into a script, then it would need to be compiled and then installed. It would be incredible if this was possible, but it seems extremely difficult and computationally intensive to allow the players to actually change a program. Depending on the complexity, it might be possible for you to write a script to check what the user has entered and then you create functions based on what the user has entered that activate certain elements of the game.

Even very, very basic coding would probably work and would be quite enjoyable on a mobile device.