Virtual Machine/Scripting/Console in XNA using C#

Started by
11 comments, last by greedygoblins 11 years, 8 months ago
You'll find that C# tends to be much more "class-centric", where value types are almost always integrated tightly in a reference object (and often exposed through Properties). Structs (especially mutable) are actually somewhat rare - Vectors are mutable value types presumably to squeeze as much performance as possible, especially on non-PC platforms which have tighter GC constraints.

You can "hook" into properties by keeping a copy of the parent object reference (which can implement an interface to make things cleaner).

For example, something like this:


public interface IHasAngle
{
Vector3 Position{get;}
Vector3 Target{get;}
}
...
class Camera : IHasAngle
{
// implement IHasAngle
}

class AngleWidget
{
protected IHasAngle ListenTo {get;set;}
public AngleWidget(IHasAngle listenTo)
{
this.ListenTo = listenTo;
}
...
}
...

AngleWidget aw = new AngleWidget(myCamera);
...


If you are trying something more general purpose, you can also use relfection as DvDmanDT pointed out.
Advertisement
Unfortunately reflection isn't an option. While the console is for debugging purposes on the PC, my game will be incorporating scripts that need access to the same functions and variables for things like AI and game logic. Reflection isn't supported on the XBox.

My solution in the end was just to turn the Variable Tracker into an object that calls a get function on every iteration of update. I was just hoping there was some way to reference the Vector without having to make a wrapper class. Thanks though guys
If anyone is interested, the Visual Scripting Framework is now available for XNA games. It allows you to customise it to your own needs, build scripts on Windows and deploy on Windows Phone 7 and XBox 360. Check out the trial to see if suits your needs...

www.greedygoblinsoftware.co.uk/visualscriptingframework.aspx

Thanks.

This topic is closed to new replies.

Advertisement