• entries
    437
  • comments
    1000
  • views
    335823

GameMonkey and Data Extensions

Sign in to follow this  

303 views

After playing with LINQ for a bit in C#, it resurrected the old "Entity Database" idea I had a few years ago. This was a concept wherein every entity in the game could be queried and accessed from script. Like so many of my ideas, it got to the prototype phase and then suddenly stalled for whatever reason seemed fashionable at the time.

I've been thinking about adding some of the functionality into GameMonkey Script by way of query extensions, possibly to the foreach iteration functionality.

So imagine the data list (table of tables, your entities would be your own bindings)


entities = {
{ name = "test1", class="wizard", hp=50, mana=10 },
{ name = "test2", class="wizard", hp=12, mana=70 },
{ name = "test3", class="warrior", hp=200, mana=0 },
{ name = "test4", class="wizard", hp=60, mana=100 },
{ name = "test5", class="bard", hp=80, mana=30 }
};


If you wanted to query all wizards with over 50 mana in normal GM, you'd have to loop:


foreach(ent in entities)
{
if (ent.mana >= 50 && class == "wizard")
{
// do something
}
}


With the query extensions, you'd have syntax similar to:


foreach(ent in entities; if(ent.mana >= 50 && class == "wizard"))
{
// do something with the wizards
}


I like the idea of grabbing results into a different table, so something like:


foreach(into results; ent in entities; if(ent.mana >= 50 && class == "wizard"));

// results now contains only the wizard data


You'd need to be able to action joins, I think something along the lines of:


foreach(ent in entities join weap in weapons on weap.id == ent.holding_weapon_id; if(weap.name == "sword"))
{
// access to all the entities that carry swords
}


Obviously, I'd have to think it over some more. I quite like the overall idea though - would something like this be useful in a scripting language?
Sign in to follow this  


3 Comments


Recommended Comments

Quote:
Original post by evolutional
I like the idea of grabbing results into a different table, so something like:
foreach(into results; ent in entities; if(ent.mana >= 50 && class == "wizard"));

// results now contains only the wizard data
You are probably aware of this already, but this is pretty much the same idea as list comprehensions in Python - certainly a very useful tool.

Share this comment


Link to comment
I do like the idea of such access to game entities, to the extent that I might try a similar system next chance I get.

However, I've never used GameMonkey. I generally use Python, and I agree that list comprehension is a great feature and similar to what you are proposing.

Share this comment


Link to comment
Please note that LINQ is generally bad for your performance when used in a game loop, since it isn't designed for optimized use of the heap (which will lead to larger garbage collections).
See http://theinstructionlimit.com/?p=254

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now