Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua, game state and game loop

Tags:

  1. Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)?

  2. Maintain game state from a. C++ host-program or b. from Lua scripts or c. from both and synchronise them?

(Previous question on the topic: Lua and C++: separation of duties)

(I vote for every answer. The best answer will be accepted.)

like image 502
topright gamedev Avatar asked Apr 21 '10 18:04

topright gamedev


People also ask

Is Lua good for game dev?

Video games In video game development, Lua is widely used as a scripting language by game programmers, perhaps due to its perceived easiness to embed, fast execution, and short learning curve. In 2003, a poll conducted by GameDev.net showed Lua as the most popular scripting language for game programming.

Can you make a game engine with Lua?

The Lua programming language is becoming increasingly popular for game development. And the LÖVE 2D game engine makes it simpler to create games using Lua. We just published a full 11-hour game development course on the freeCodeCamp.org YouTube channel that will teach you how to create games using LÖVE 2D and Lua.

Why is Lua used for game scripting?

Lua is a popular choice because it's small, portable, hackable ANSI C code base; easy to embed, extend, and -- most importantly for game developers -- it has a minimal runtime footprint (one of the fastest interpreted languages).


1 Answers

My basic rule for lua is - or any script language in a game -

  • Anything that happens on every frame: c++
  • asynchronous events - user input - lua
  • synchronous game engine events - lua

Basically, any code thats called at >33-100Hz (depending on frame rate) is C++ I try to invoke the script engine <10Hz.

Based on any kind of actual metric? not really. but it does put a dividing line in the design, with c++ and lua tasks clearly delineated - without the up front delineation the per frame lua tasks will grow until they are bogging processing per frame - and then theres no clear guideline on what to prune.

like image 50
Chris Becke Avatar answered Sep 19 '22 17:09

Chris Becke