Sunday, November 25, 2012

INFR 3110 - NGScripts

GDW is due soon.

Feeling the pressure, and it doesn't feel good. Crunch is upon us and honestly, I haven't ever been so worried for a GDW deadline ever before. In previous semesters we've always had a working game a week or two before it was due, and would just spend the remaining time polishing. This time though, we're behind.

Time to bring this back.

Regardless though, in this blog post I'm gonna talk a bit about the scripting system we have in our GDW game. It's probably the engine component that I'm most proud of that I added into the game because I personally think it's pretty freaking cool.

In previous GDW games, I always hard coded the game logic. This included everything, from enemy behaviours, events, and so on. As you can probably imagine, things get really messy really fast, especially if you wanted some complex enemy behaviours.

See that scroll bar to the side? Pretty much 90% of it from this point down is the update function.

Code gets really messy and long, which we don't really want.

Since we wanted some more complex behaviours in our game, and we wanted an engine that was scalable and easy to manage, I decided to try my hand at creating a scripting system in our game. So one weekend I sat down and came up with a base for the scripting system, and thus NGScripts were born.

Yes, my ego knows no bounds. We've went over this before.

So how it works is that I wrote a parser that parses a text file for keywords and values. Then, based on the keywords and values inputted, I used a bunch of member function pointers and other things to essentially recreate the script into C++ logic.

Then, the scripts can be attached to an object in the game, and when the object is updated, so will the script. Whenever a condition is fulfilled, then the associated action will trigger. It also has a property section so we can also change object values in the script too.

Just like that, and it'll work.

I'm actually really happy with how it turned out. I currently can check for a bunch of conditions such as whether or not the object's health is below/equals/above a certain point, whether or not it is closer/equals/farther than a distance from the player, whether or not enough time has passed, etc.

When the condition is true, then it will activate the action which will do something such as change the AI state or apply a force. It made me feel pretty giddy to see it all work in the game, but it's still a work in progress, many more improvements can be made, and a lot more stuff can be added.

Also I need a better interface for the editor/generator.

No comments:

Post a Comment