Jump to content
  • Advertisement
Sign in to follow this  
Kraur

Examples of Lua?

This topic is 2690 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

Hey everyone, I hope this is the right place to post this.

I've currently been learning and getting used to Lua and I'm loving it. I've tried many different languages and Lua is the only one that I am really enjoying. But I was wondering, what is Lua acctually used for? I know it's been used in lots of major games and you can create cool add ons in WoW or SCII, but what is it used for in another type of game? I've heard it's used for small things, but what exactly are those small things?


I hope someone can help! Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Pretty much anytting. A good example of somehting that might be scipted (doesn't have to be lua) is AI/UI. I use lua for my AI, for my UI and to handle some of my game states. You could write the majority of the game in it if you really wanted to. You could use it for initialisation, just to store data. I have a single lua script that gets run, which in turn runs other scripts, sets up locations of resources and so on. Its great because you don't have to recompile your code to make changes.

Share this post


Link to post
Share on other sites
I wrote a description of how I'm using Lua in my current game in my journal here. I use it slightly differently than I used to when I first started with it. Once upon a time, I implemented the main "guts" of my games in C++, and only called Lua functions for things such as AI functions, trigger actions, and so forth. Now, though, the bulk of my game sits in Lua, and I only call into C++ for things that need to run very efficiently: rendering, path-finding, collision detection, etc....

Outside of Goblinson Crusoe, I use Lua very extensively for my all-purpose, general-use experimentation and prototype language. For instance, I use it when experimenting with procedural generation. In this journal post I include a link to a binary build of my general-purpose tool. It is a Lua command-line interpreter with my own extensions built in to it and exposed via tolua. The build includes scripts for the Minecraft-style level generation system I tinkered with, described in this journal post.

Lua is extremely useful, both as a scripting/configuration tool, and as a standalone language.

Share this post


Link to post
Share on other sites
Thanks for the replies!

I was thinking of this 2D game idea which is actually very basic and I wanted to use C++ with Lua for it. So I would use C++ for the things like Collision Detection, Game Menus, Character Movement and then use Lua for shooting (like a bullet), power ups, AI, UI, etc. ?

I would prefer to do almost all of the game in Lua, the only reason I'm using C++ is so I can use Lua within the game :P

Share this post


Link to post
Share on other sites
I ended up using Lua in my game/engine for data files. I wanted them to be human-writable, so instead of using horrible XML I now have things like:


entities = {
player = {
prefab = "prefabs/player.nspf",
pos = "0 10.1 50"
}
}


A prefab is what I call a blueprint for an entity. Eventually I'll have a way to "compile" data files into a binary form. But leaving them as Lua for now has another benefit: you can write code in your data files. Recently I added the ability for trees to go transparent if they block the view. To test it I wanted a bunch of trees, so I wrote a function to create the trees and just called it a bunch of times to make a row of them.

Share this post


Link to post
Share on other sites
If your target platform is PC, LuaJit 2.0 + FFI interface is fast enough to do it all in Lua now... Though be aware programming in a dynamic language like Lua is different than C++ which is much more structured and static.. Creating a C DLL interface to give LuaJit + FFI direct access to the low level stuff, you have the flexibility of Lua + the absolute speed of C. Basically its a game changer. Good Luck!

-ddn

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!