Game Development Community

dev|Pro Game Development Curriculum

SimSet getIndex console method

by Daniel Buckmaster · 10/18/2007 (2:05 pm) · 2 comments

I know I said the next resource I submitted would be about crosshairs and context actions and all that. Sorry, I lied. In the first place, it was giving me trouble, and in the second, it would have been a long-ish resource to write up. So I'll keep working on it, and in the meantime, here's a cookie.

This resource, however, is here now. It will add a console method to the SimSet class that returns the position of an object within the set. Sounds useless, right? Well, it isn't for me. I'm doing some things with interaction between a SimSet and a GUI, related to switching weapons. And since I wrote it, I figured I'd share.

So here's what you do.

Open the file simBase.cc in the engine/console folder. Look for this line:
ConsoleMethod(SimSet, getObject, S32, 3, 3, "set.getObject(objIndex)")

Beneath the console method it begins, add:
ConsoleMethod(SimSet, getIndex, S32, 3, 3, "set.getIndex(objID)")
{
	U32 objectID = dAtoi(argv[2]);
	S32 index;
	for(index = 0; index < object->size(); index++)
	{
		if(((*object)[index])->getId() == objectID)
			return index;
	}
	return -1;
}
Recompile, and you're away!

Disclaimer: This is probably the most inefficient way possible to do this simple task. It performs well enough for me - that is, it doesn't cause my computer to crash and burn.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
10/19/2007 (7:57 am)
No Daniel, do not sound useless at all. Ive needed this one sometimes, thanks!
#2
10/25/2007 (2:32 am)
I can't believe this wasn't there already.