Jump to content

  • Log In with Google      Sign In   
  • Create Account


Why LUA Script ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 andrei94   Members   -  Reputation: 134

Like
0Likes
Like

Posted 09 April 2012 - 12:54 PM

Hello everyone ! My name is Andrei and i'm 18 years old. I'm interested in game development and i started to read some books...now i read something about DX11 and its very interesting but in a section about game engines i heard about LUA scripting and heard that it's a good practice ... But why to use it if C++ can do the same thing?


I just wanna some opinions pro's or con. Thanks for help guys ;D

Sponsor:

#2 Jebbs   Members   -  Reputation: 276

Like
3Likes
Like

Posted 09 April 2012 - 01:53 PM

Lua is a scripting language and it is very common to do a lot of the programming in a scripted language. Most(if not all) commercial game engines provide some sort of scripting support. The reason people use scripting languages is that it helps cut down on development time. For example, you're working on an enemy's AI and it's not working quite right. If you coded it's logic in C++ you would have to recompile the code to test any changes. With a scripting language you just make the change and the new file is loaded into the system.

As you said, everything you can do in a scripting language you could do in C++, but anything that helps speed up production is a good thing, right?

Of course, there is a little overhead to run the scripting interpreter on top of your game but with today's systems you should see much of an impact.

#3 SimonForsman   Crossbones+   -  Reputation: 6032

Like
2Likes
Like

Posted 09 April 2012 - 02:33 PM

Also, on top of not having to recompile you can actually modify scripts while the game is running and see the result immediatly, it can also make it quite easy for non programmers (level designers for example) to add custom behaviour to the game without having to ask the programmer to add every tiny little feature.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#4 shadowisadog   Crossbones+   -  Reputation: 2396

Like
1Likes
Like

Posted 09 April 2012 - 05:47 PM

It also provides a way to make your game moddable by your players.

#5 Ravyne   Crossbones+   -  Reputation: 7112

Like
1Likes
Like

Posted 09 April 2012 - 06:35 PM

In addition to the moddability and decreased turn-around time on modifications that has been mentioned, it also has to do with tooling and productivity.

You can leverage C++ in ways that yield a great deal of performance, but at the same time it has essentially no guardrails and pitfalls are not uncommon -- things like memory leaks, maintaining ownership of resources correctly, and the rabbit-hole of premature optimization. In truth, a large part of the game-specific elements don't need all the performance that C++ can offer you, and so it doesn't make sense to expose that part of the code to all the potential pitfalls. Instead, you can implement those parts of code in a language that is safer, more productive, and "efficient enough" -- and leave the core engine to more-experienced programmers using C++.

There still exists a certain inertia among game developers that "all code is performance-critical" and for a certain type of developer -- say, those pushing the limits of AAA console gaming, it's not entirely untrue. However, this notion that this is true of all games is something that dogs some in the industry, and far too many of those aspiring to be in it.

Objectively, yes, performance matters (you can measure it it, therefore you can rank it), and 300 frames per second is "better" than 270 frames per second -- but subjectively, no one's going to notice whether your game runs at "only" 80 or so frames per second. In the end, all that matters to the consumer is "does this run well enough on my hardware?" and the number of consumers you want to reach is defined by "what hardware can I make this thing run well on?"

#6 jbadams   Senior Staff   -  Reputation: 17912

Like
4Likes
Like

Posted 09 April 2012 - 07:26 PM

Looks like the benefits have been covered pretty well:
  • Faster/easier iteration when testing new ideas (because you don't need to recompile).
  • Allows for non-programmers to take an increased role in development.
  • Can protect the programmer from some mistakes that can occur in lower level programming languages.
  • Can easily allow players to mod the game.

So far I only see one disadvantage listed though: code written in a scripting language has a run-time overhead and may execute slower than lower level code. As already mentioned, this isn't a big problem the majority of the time, and the benefits above are usually well worth a slight hit to performance -- it is something to be aware of though, and depending on your needs means that you might not want to use scripting for everything.


Another disadvantage I wanted to list is that you need to spend a small amount of development time initially setting up your scripting language so that it works. In a great many cases the advantages listed above will outweigh this small investment in time and make it well worth the additional effort, but if you are creating a particularly small and simple game it might be worth considering.


Overall I personally think the inclusion and usage of a scripting language (Lua, Python, JavaScript, etc.) is well worth it for most projects above a certain (very simple) complexity, and is well worth considering. As a beginner who is just learning however, you might want to put it aside as something to look at more after you've spent more time learning your chosen lower-level language as well as programming in general.

#7 yckx   Prime Members   -  Reputation: 1163

Like
1Likes
Like

Posted 09 April 2012 - 10:04 PM

Yes, Lua may execute slower than C++ code, but that shouldn't be seen a reason not to use it. First, make it work. Then, if profiling shows it to be a bottleneck, you can optimize, which may include migrating some routines from Lua to C++. But honestly, JTippets's Goblinson Crusoe is written almost entirely in Lua. The C++ bit is an extrapolation of the Lua interpreter that comes with the Lua distribution.

There are other languages that can be used as scripting languages, such as Python and JavaScript. One thing I like especially about Lua, though, is that it works well for data description, which can be nice if you're into a more data-driven approach.

#8 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 10 April 2012 - 11:34 AM

lua is great... and lua is horrible...
lua is great as once it is setup and going, it is wonderful, you can modify your game as it plays, not having to recompile and get to the state that you were testing
lua is horrible because setting it up can drive you insane. Well, at least me. Oh, and the documentation isn't always that helpful, for instance, lua_pcall(L, NumArgs, numRet, 0) when I first started using it I had my numArgs being the number of arguments the function needed, the documentation didn't specify specifically that the function call was also an argument, so it was failing on me. The documentation wasn't wrong, it just wasn't helpful enough for an impatient tiered student as of myself find understand it how it was meant to be.

I would recomend that you look into luabind... It can be hard to set up due to the lack of examples to follow and it can be made even harder if you can get impatient.
but once you have it implimented it can be really useful, I am currently working on my own luabinding, yes, it is driving me nuts, but the sheer flexibility it offers is what keeps me going at it.

#9 andrei94   Members   -  Reputation: 134

Like
1Likes
Like

Posted 10 April 2012 - 11:45 AM

thanks everyone for help :D now it's clear

#10 djofdifjpodjfpodkpofdpofpd   Members   -  Reputation: 120

Like
2Likes
Like

Posted 10 April 2012 - 07:12 PM

Oh, and the documentation isn't always that helpful, for instance, lua_pcall(L, NumArgs, numRet, 0) when I first started using it I had my numArgs being the number of arguments the function needed, the documentation didn't specify specifically that the function call was also an argument, so it was failing on me. The documentation wasn't wrong, it just wasn't helpful enough for an impatient tiered student as of myself find understand it how it was meant to be.

Take no notice of this, Lua's documentation is excellent.

falconmick maybe you should read the documentation next time it clearly tells you the protocol as lua_pcall links to lua_call

As people are mentioning the speed of Lua compared to C and C++, if this does become a problem you can always you use the excellent and blazingly fast LuaJIT which supports quite a lot of platforms now with speed being the same or close to C code.


edit: I just can not let it go :) The Language's name is Lua not LUA,

#11 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 10 April 2012 - 09:28 PM

I've always thought of args as things that are passed into functions, not everyone is a whiz on this forum.

the downvote button is for not agreeing with someones opinion. That is all it was, I gave a first hand experience of how I have experienced LUA (:3) and even given a description of myself so they can understand why I would say what Ive said


lua needs time to be build in correctly, it is somthing that should be planned and implemented in segments.

#12 djofdifjpodjfpodkpofdpofpd   Members   -  Reputation: 120

Like
-3Likes
Like

Posted 11 April 2012 - 04:53 AM

the downvote button is for not agreeing with someones opinion.


Congratulations, you have earned the award of being downvoted by me again.
Grow up, I sent the private message to explain the reason and to tell you it was me that downvoted you please do not use private messages to insult me.

#13 jbadams   Senior Staff   -  Reputation: 17912

Like
1Likes
Like

Posted 12 April 2012 - 01:11 AM

This is not the place to discuss the reputation system or your down-votes, and certainly not the place to air a private dispute. If you feel you are being treated unfairly, or that someone is misusing a site feature, use one of the many "report" links around the site and/or contact a moderator.

dmail: "falconmick" was reasonably clear that he is inexperienced and that he was just sharing his own experience with Lua, and I don't think his intention was to mislead anyone. We are in the "For Beginners" forum here, and correcting a beginner's mistake or taking a moment to highlight the fact that not everyone shares a particular opinion is great, but having been shown the contents of your PM I would suggest that you could be a lot more tactful in future.

falconmick: In future, please try not to lash out at other members; if you feel the contents of a private message are abusive or insulting you can use the "report" link at the bottom-right of the message to have a moderator review the situation for you.

Any further off-topic replies will be deleted. You have been warned.

Edited by jbadams, 12 April 2012 - 01:31 AM.
Added personalised feedback to each user after having been shown the contents of the private message in question.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS