Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Oct 2002
Offline Last Active Mar 22 2012 04:39 AM

Topics I've Started

Can IronPython access members of a C# class instance?

20 March 2012 - 08:51 PM

So, I can get an instance of a C# class just fine to IronPython, but I can't seem to do much of anything with it's members or functions. Is there anyway to get around this problem? The IronPython documentation and my searches hasn't led me very far on figuring this out for the past several hours.

Here is a simplified example of what I'm trying to do:
class Unit
	public int HP { get; set; }
	public int Attack { get; set; }

	public Unit(int HP, int Attack)
		this.HP = HP;
		this.Attack = Attack;
	public void PointlessFunction() { }
	public override string ToString()
		return "HP: " + HP.ToString() + " Attack: " + Attack.ToString();

class Program
	static void Main(string[] args)
		ScriptEngine Engine = Python.CreateEngine();
		ScriptScope Scope = Engine.CreateScope();

		Scope.SetVariable("Unit", DynamicHelpers.GetPythonTypeFromType(typeof(Unit)));

		// declare instance of Unit
		Engine.Execute("u = Unit(10,5)", Scope);

		// display Unit instance
		Engine.Execute("print u", Scope);
		//HP: 10 Attack: 5

		// Try to change something
		Engine.Execute("u.HP = 20", Scope);
		//Unhandled Exception: System.MissingMemberException: 'Unit' object has no attribute 'HP'

		// Try to run a function
		Engine.Execute("u.PointlessFunction()", Scope);
		//Unhandled Exception: System.MissingMemberException: 'Unit' object has no attribute 'PointlessFunction'

[XNA] 2D Flashlight Vision

10 June 2011 - 03:27 AM

Okay, so I have a simple 2D tile-based top-down game.

I have these guards that are trying to spot the player. They have a field of view that I want to represent as a flashlight glow that lights up the area. This area will be where the guard can see, so I'll also need to detect if the player is inside one of the guards' views. Tiles can also block their vision.

I guess I want something to look like this:
Attached File  flashlight_vision.png   1.38KB   69 downloads

I've seen stuff about ray tracing or field of view, but I'm not sure where exactly to start first.
Posted Image

XNA Small Solid Texture2D

09 May 2008 - 03:10 PM

So, with XNA. Anyway to go about making a small solid Texture2D without loading an image? Like generate a 2x2 white image to use for drawing rectangles or whatever.

2d and 3d puzzle solvers

10 November 2007 - 12:21 AM

Hi, I got two similar AI projects I'm working on. Trying to build a solver for a 2d sliding puzzle and a 3d Rubiks Cube. I'm trying to build these as what a human would solve like, so I don't need super efficiently. So, with both puzzles, most humans would solve First row, then work their way to the bottom. I assume with the 2d puzzle, I can use a 2d array to store everything. But how do I move the pieces toward the goal? And how do I deal with the last two rows, which can require a bit of shuffling. I have no idea the best method to store a Rubiks cube (I haven't done much 3d math). And also no idea how to handle the rotations of the cubelets (which I assume is going to be based on data structure I use. I know how to solve a cube with the basic algorithms, I just need a starting point. I assume there is some overlap on the theories between both.

Getting Last Object inserted in STL Container

13 July 2005 - 11:47 PM

I'd like to be able to get access to the last object I've added to my containers. Namely for a Vector, List or Map. For an STL Vector it seems like I can do *(myvector._Last-1) //for VC6 *(myvector._Mylast-1) //for VC.Net 2k3 I suppose for an STL Map, I could keep a copy of my Key when I add to my Map, but I'm sure there might be a more elegant way. And I'm clueless on an STL List. >.<; (Tho it should be simple.) It seems like I'm also going to have to keep track of my compiler versions too (or Maybe STL versions), since it seems to differ. I'm currently using MS compilers, so I care mostly about these options as of right now. -Daichi