Jump to content
  • Advertisement
Sign in to follow this  
brightknight

gameplay programming: when to use lua and when to use c++

This topic is 763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need some things cleared out as i cant seem to find anything that explains this to me,

Anyway Say i was making a game, this hypothetical game was about getting to the finish line before the npcs,

the player can walk run and jump and so can the npcs. and the point is to finish first. When making this game what parts would i code(c++) and what parts would i script(lua),

 

no answers involving things like graphics physics or anything done by the game engine as those would obviously be written in a low level language.

Share this post


Link to post
Share on other sites
Advertisement
Lua scripts are easier to treat a resource. You can have a file represent an enemy type or another dynamic object in your game. This file can include the name of a script to use as the object's behavior.
This makes extending the game easy to do, and you really begin to see the benefit when your game has many different types of dynamic objects. You do pay the cost of having to create a binding layer between lua and c++. So the benefit may not be worth it if you aren't going to have many types of objects in your game.

Share this post


Link to post
Share on other sites

With Lua being faster and easier to write, I'd try to push as much as possible into Lua. What's the point of a scripting language if you don't use it when you can?

This then leaves the "lua is too slow for this" parts in C++ (as well as the lua glue to the C++ libraries).

 

However, that part could be a lot smaller than you'd think at first sight.

Share this post


Link to post
Share on other sites

With Lua being faster and easier to write, I'd try to push as much as possible into Lua. What's the point of a scripting language if you don't use it when you can?

This then leaves the "lua is too slow for this" parts in C++ (as well as the lua glue to the C++ libraries).

 

However, that part could be a lot smaller than you'd think at first sight.

So basically lua it as much as possible until you need c++ for performance reasons,

Share this post


Link to post
Share on other sites

However, that part could be a lot smaller than you'd think at first sight.

Especially if you use LuaJIT :D Damn, it's fast.

So basically lua it as much as possible until you need c++ for performance reasons,

If you enjoy programming in the language and find it more productive than writing C++ code, sure!
I've worked on half a dozen console games (this-gen and prev-gen) that use Lua as their main language, and C++ for engine / high-perf stuff. The reason for that is that it's much faster to write a game in Lua than it is to write one in C++ (i.e. productivity).

Some people don't like 'scripting languages' (e.g. Epic/Unreal voted on which scripting language to use in UE4, and C++ won... :o), so in some games you'd only see it used as a DDL for entities, triggers, etc...

Share this post


Link to post
Share on other sites

However, that part could be a lot smaller than you'd think at first sight.

Especially if you use LuaJIT :D Damn, it's fast.


Unfortunately, LuaJIT decided to stick with the Lua 5.1 language, and not upgrade to newer versions.

Share this post


Link to post
Share on other sites

"core" or "non-core" isn't that relevant, more relevant is how often a thing must be done.

 

In that sense, it depends what "shooting" means. If you mean user pulling the trigger, that happens 5 times a second or so, max? (Billy the Kid player)

If "shooting" means "moving a bullet", that happens once a frame, say 50Hz?

If "shooting" means 1000 enemies all moving bullets, that's say 50KHz?

 

My guess is that anything less or equal to once a frame is pretty feasible. A game like CorsixTH does pretty much everything in Lua, and that works even without LuaJIT.

Edited by Alberth

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!