Jump to content
  • Advertisement
Sign in to follow this  
VitaliBR

How using LUA in my game?

This topic is 2824 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 would like to start using scripts in my game, preferably LUA.
But I have no idea how to do, and what could help me scripts

Share this post


Link to post
Share on other sites
Advertisement
The first edition of Programming in Lua is available for free online, specifically part 4 discusses the C API. Also there are various binding libraries like LuaBind, toLua++, SWIG, ... that simplifies it.

HTH.

Share this post


Link to post
Share on other sites
For example. I'm using Crazy Eddies GUI System (CEGUI),it has support for LUA Scripting:

http://www.cegui.org.uk/wiki/index.php/Handling_Events_from_Lua

In my code (C++) I have a ScreenManager (singleton) that the call when you press a button that makes trading screen (exemple: "back")

In my code:
if(pos_mouse == pos_button)
ScreenManager->ChangeState(m_pDevice, new MenuState()); //back the main menu


How could I do it in LUA?
I looked about and I doubt I can access my Singleton ScreenManager with LUA?

Share this post


Link to post
Share on other sites
okay okay... that is too complicated.

start with something simple in lua. for example, how do you construct a level? do you have a file that you parse?

try parsing it in lua and creating objects in the level from lua. This is an extremely powerful thing to do, as it allows you to load levels and change levels at runtime

Share this post


Link to post
Share on other sites
So your game is a 2d side scrolling game with lots of interacting objects and I assume levels. Programming in Lua is like programming in any other language but if your coming from a C/C++ background you might be unfamiliar with the dynamic nature of Lua and languages like it.

On the Lua side you need to make managers (globally accessible objects which manage things, be it other actors in the level, fx, etc..). Lua is fast and robust enough to hold probably 90% of your game logic.. so no need to create managers on the C/C++ side for these things..

When you start up Lua you load a script and run it, it should then setup and create these managers which other scripts depend on. You should also use OOP techniques in Lua to decompose the problem space.. Once these managers are created, you can then periodicly every frame give CPU time to the scripts be calling back into it using some accessors functions exposed to the C/C++ side from Lua.

Lua objects should for the most part self manage without any dependency from the C/C++ side and should release rsrcs they acquire when they go out of scope. An example of a Lua object would be the player. The player would be a Lua object which contains member variables for health, position, player state, player physics, animation to play, etc.. Things which the player can interact with are also Lua objects such as a barrel. A barrel can be derived from generic Lua base class of type object (again using OOP in Lua)... etc.. This should point you in the right direction.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
Thank you for your help friend :D

I'm really noob at LUA and must study hard

Do you know any tutorial or book that teaches LUA creating a simple game?

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!