0

I am looking for a virtual machine I can embed inside a game.

The idea is that I create a game world and two avatars. Inside the avatars I embed a virtual machine that can interact with the avatar in the game world using an api, like:

move_forward()
turn_left()
turn_right()
sense()
etc.

In each tick i will allow each VM to update X ticks progressing each. Two different programs would then be uploaded to each VM and be executed independently. The whole setup should be robust against crashing programs inside the VM.

I would prefer to work in Python, and my environment is C# but I am open for suggestione.

The idea is heavily inspired by the game GunTactyx, but I find the language used there too narrow, as I aim it to be a learning platform to move further into programming.

Do you know any VM that allow me to do this?

kind regards

Jesper

Seki
  • 11,135
  • 7
  • 46
  • 70
TAXfromDK
  • 43
  • 3

1 Answers1

1

I would use Lua, which in my experience is more heavily used in games than python.

You can use debug hooks or coroutines to limit the number of instructions being executed at a time. Here is a post on someone doing something similar to you: http://lua-users.org/lists/lua-l/2009-03/msg00008.html

In terms of robustness against crashing: "Because Lua is an extension language, frequently embedded in an application, it cannot simply crash or exit when an error happens. Instead, whenever an error occurs, Lua ends the current chunk and returns to the application." http://www.lua.org/pil/8.3.html

If you want to use C# to wrap Lua, try

http://luaforge.net/projects/luainterface/

https://github.com/NLua/NLua

Also check out this post for a discussion on Lua Vs Python:

https://stackoverflow.com/questions/356160/which-game-scripting-language-is-better-to-use-lua-or-python

Community
  • 1
  • 1
LouD
  • 3,776
  • 4
  • 19
  • 17