• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Shaarigan
      Hello Designer Community,
      we havent seen for a while but now, as I'm doing some more advanced game design again, I thought visiting you to get some feedback
      [deleted by moderator]
      As I'm in the design phase now need to think about what makes a kind of multiplayer/online/mmo RPG/whatever uses similar mechanics playable besides mob-farming/boss raids (if existing) or PvE, PvP; what makes even small Quests interesting. I now this has been asked a whole time but I decided to ask this again for the background of automated content creation as a desired result for the Spark ecosystem. What kind of quests or quest components could be generated too that are not listed below to make the game more interesting?
      Collect X of Y Carry X to Y (you maybe need to find X first) Kill X of Y Talk to X Kill X As I've played many hours of different RPG's (solo, online, mmo) there are always these five archetypes of core quests or core quest components that may sadly lead to just skipping the often more or less trivial storyline if existing just to raid through the quest for getting the XP and loot items. This isnt fun and even a good story (bad telled) may not keep the longterm gameplay experience very valuable.
      This may also be a bigger problem for auto generated quests so what should the generator also take into account to lead to an acceptable result?
    • By xaviersythe
      Website | Music | Youtube | IndieDB

      What is it?
      Nanoforge , is a first-person, sci-fi sandbox-adventure game, built in Unity (C#).
      What have we accomplished?
      What do we offer?
      What do we need?
      C# Programmers
      C# experience required Prior experience with Unity a plus Communication skills Note: Other programmers, LEVEL DESIGNERS, and other roles are also invited to apply!
      JOIN NOW
      Where's the gameplay footage?
      Just as AAA studios do, we keep our gameplay footage closely guarded, as it reveals our innovative take on sandbox gameplay. Additionally, releasing pre-release footage with non-final visuals could confuse potential players into believing that the footage is of the final version of the game. That said, here's a tiny look at our teleport effect.
      How does the game compare to games like GMod or Minecraft?
      We've surpassed Minecraft's Creative Mode in terms of functional features, and are closest to Garry's Mod in terms of planned feature set.
      I'm not experienced enough to join this project.
      That's not a question! There's always a place on our team for someone passionate about game development. Willing to learn?
      Any questions? Ask away!
    • By WolfWin
      Happy Thursday!
      Looking for some recommendations for apps that help plan/organize classes and methods for a project (something like xmind but for programming). Also Looking for good app beyond GitHub for project coordination.

      Thanks in advance :3

    • By April_X
      Hi, I am new here, may I ask: do you guys have any suggestions about whether I should go to GDC, or Unity events during GDC, or, actually, any meetups and local events in LA, when I am more of a mature developer/when I already finish up most part of my game demo, or now? From career development perspective. Now I am not a total beginner, but I am not a mature developer either, kind of like in between X-0
      Please forgive me if this question is silly or naive. Thank you!
    • By Bronco78th
      Hi All,
      Im running through some video tutorials in C# as im newbie. One thing im doing is adding lots of comments to the code so I can go back and revisit the code later and know exacly what is going on.
      What id also like to do is store the code snippets in an easy to find place so I can reuse/analyse them later. 
      I kind of just want a long scrolling page with all my code and commented snippets on that I can use as reference later which also maintains the snippet  format and is of course searchable.
      There seems to be a few apps as well as Git Hub etc to store code snippets but im just wondering which one from a newbie perspective works best for you and why?
      Kind Regards,
  • Advertisement
  • Advertisement
Sign in to follow this  

Lua scripting woes

Recommended Posts

I need some advice. After I changed my scripting language from in-memory C to Lua I've had numerous problems I've never encountered in other languages.

Prototypes? Type signatures? Calling functions with any number of parameters?

How do you deal with all the random bugs you can get that you have really no way of determining the cause of?

If I call a function with one less parameter than it should have, I might just get a Lua error somewhere else in the script. At a later time.

What do you do to make your code (which isn't bottlenecked at all, so there is tons of room to add checks and balances) more correct and more sane?


If I scripted sanely in C I would rarely have these issues. For example any pointers passed between the engine and the script goes through a sanitizing stage where it actually checks if the pointer points to an actual valid existing entity. If it sounds like I am regretting the change, I don't know how to answer that. Lua can construct tables and pass them around, which is very nice, unlike C where I would have to malloc (and that is just not going to happen).

Edited by Kaptein

Share this post

Link to post
Share on other sites

Things like this are why I have a love/hate relationship with Lua. :)

You might want to add validation checks for your function arguments and throw errors when something goes wrong. You'll want your host application to print out the call stack on errors so you can track down where the problem occurred. Ultimately, though, you need to exercise all your code (whether at runtime or as part of a test framework) to make sure everything is sound.

The problems you're experiencing seem common to all dynamically-typed languages (including JavaScript) since there's fewer ways for the language to help you out than with statically-typed languages (like C). I don't think there's an easy solution aside from being careful with your code and disciplined with testing. Dynamically-typed languages usually work great for small things but start getting harder to use as projects grows in scope.

(Background: I worked on several commercially-released titles that used Lua extensively and added Lua scripting to an older game as part of an unofficial patch.)

Share this post

Link to post
Share on other sites

Yeah Lua is great, but very unpalatable to begin with when coming from a C background...

When passing pointers from C to Lua and back, you can either pass them as a light-userdata, which is equivalent to a void*, or use a heavy-userdata which allows you to attach a metatable that you can use for runtime type validation.

Unless you actually want to write code in the prototype paradigm, you'll likely just use metatables to implement an OO-style class system and then forget about them. 

When writing OO style code, you can use one of two main styles:

className.method( self, args... )


self:method( args... )

If you use the first style, then it will be closer to a statically typed language, as you're constantly writing the name of the class that you expect an object to be. It's also quite a bit faster (on vanilla Lua / non-LuaJIT -- JIT'ing makes them both just as fast really).... but the first style is ugly :D

Inside your methods, you can check the metatable of each object (including self) to see if it really is of the expected type -- the details of this depend on how you choose to implement classes/OO! You can also check whether any of your arguments are nil (which will happen if it's called with too few arguments) or whether any spurious extra arguments were passed or not. You could use a pre-processor to strip out these debug assertions from shipping builds if required.

Getting a good debugger is also very useful. I'm using "tilde" at the moment, but am looking to switch to something else soon....

If you want to support runtime script reloading, then that will also affect the way you write your code. In C, you might write some code like:

foo = foo ? foo : 42; // if foo is zero, set to 42

In Lua, when creating a new global table, you might write:

foo = {}

But when reloading your script, this will assign foo to a new table (leaving some of your code potentially still referencing the old table!). So, you can instead write:

foo = foo or {}

And then if you reload the code, the foo table will not be recreated.

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  

  • Advertisement