Jump to content


Scripting implementation questions...


1 reply to this topic

#1 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 23 November 2006 - 04:40 PM

I'm currently working on a game using Ogre for the graphics. I'm having a few problems with the engine code, so I'm writing a simple MapReader which reads XML files. In the map files, entities are defined like so:
<Entity type="enemy" name="Enemy1">

    <position x="1" y="2" z="3">

    <script file="enemyAI.lua">

</Entity>
As you can see, a LUA script can be attached to each Entity. I've never worked with any kind of script engine before, so I have a few questions...

First, I assume each Entity will need it's own thread in which its script can be run. Is this correct?
Second, could I possibly run multiple scripts for each entity?

This question is actually related to the MapReader, but I figured I would throw it in...

How would I handle dynamic entity creation with a script like this? My game is set in various towns, so I would like to spawn entities when the entity count of each type (civilian, enemy, etc) drops below a certain number. Will I need a different map system for this type of thing?

Thanks!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 23 November 2006 - 08:28 PM

cypher543 said:

First, I assume each Entity will need it's own thread in which its script can be run.

I would recommend against this; threads tend to be "heavy" (consume a lot of OS resources), and so you don't want to have an individual thread for each of the possibly hundreds or thousands of entities in the game.

Moreover, this really depends on how you have set up the entity system. How does the entity code interact with the engine code? One way to do it is to have the entity code register event handlers that are then called by the engine when events happen. In this case you don't really need threads, the engine code can simply call the entity code when it wants to. Another way to do it is let each entity have an 'update' method that gets called every so often. In this case you can have one thread that just loops through and updates all entities, sleeps till the next cycle, and repeats. And of course you could combine these approaches together or use others.

Quote

Second, could I possibly run multiple scripts for each entity?

Of course, you can do whatever you want. You have to decide how you want multiple scripts to be used and how you want them to interact with each other and the engine.

Quote

How would I handle dynamic entity creation with a script like this? My game is set in various towns, so I would like to spawn entities when the entity count of each type (civilian, enemy, etc) drops below a certain number. Will I need a different map system for this type of thing?

Well, again, it's up to you. I'm not really sure why you're asking us whether you can or can't do something with your own map format, which you're designing and have complete control over. :whistle: You could for instance have a script associated with the map as a whole that would monitor conditions and perform the spawning. Or you could have an invisible spawner entity that would do it.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users