Sign in to follow this  
ConorH

Using scripts for AI, worries about performance

Recommended Posts

Im in the early stages of creating a simple little RTS, and for each unit, I was thinking of letting scripts do all the work. Allowing the Lua script writer some funcions to check the units health, whats around it, make it fire etc. But my main concerns are; If I were to allow the scripter complete responsibilty for units, would allowing Lua to do all of that work be a big dent in my performance? If it is viable, how is this done? I mean, every time the game loops and gets to the part where the units must calculate their next action, do I run the script again? It seems the only way atm. Or could it be done by a set of conditional scripts or functions. So if the unit is being attacked, the prog runs func x in the lua script, and if the unit is told to attack something, the prog runs func y to decide the best way. I would prefer to use scripts more than I have been doing, and this is my first time with Lua as well. All help is appreciated

Share this post


Link to post
Share on other sites
Best thing to do is to write a few test scripts and measure the performance.

If you have a large amount of units then don't update them all at the same time - spread them across frames.

Lua is great but just be aware that you can you yield functions to give control back to the main lua thread from within the scripts and pick up again where they left off - this comes handy to stop a single script consuming everthing.

Overall I wouldn't worry too much about LUA - its pretty good at what it does and pretty lightweight (at least it used to be... not used it in a while).

Share this post


Link to post
Share on other sites
I recommend using event callbacks for altering behavior, but having the low level logic of actually performing the behavior mostly in native code. You should avoid having a 'tick' or 'update' function in scripts. Usually that is a sign of something that should be done on the native side. You can set up event callbacks for when a unit is attacked, healed, spots an enemy, etc and pass the relevant parameters to each callback based on which callback it is. Do as much as you can in script. If something proves slow you re-do it in native code, or partially automate it with some native helper functions.

Share this post


Link to post
Share on other sites

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

Sign in to follow this