What are Benefits of Adding a Scripting Language to a Game?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: What are Benefits of Adding a Scripting Language to a Game?

Post by MadPumpkin »

GyroVorbis wrote:
MadPumpkin wrote:So every time that you run a lua script, it will reload the file (if you don't have it purposefully set up otherwise) and redo all of the commands and scripting you have in the file.
Uh, not really. Sure, if all of your logic is global, and you're only using luaL_dofile(), but that's a REALLY terrible way to handle it. Then you truly are making a blocking IO call, reading a file, parsing through it, and executing it every time.

You're supposed to have initialization logic global (or in an init function), then have your operations split into a series of functions that you are directly invoking whenever you need to. After you call luaL_dofile() once, the script has already been "compiled" by the interpreter and is stored in the state, ready to go.

Sure, you CAN reload the file at each execution and get away with it on a modern PC, but there is no way in fuck you could do that frame-by-frame in real-time on any kind of console or older machine (I've tried it).
Yea I guess my wording was off, I mostly meant that you can make it just reload the file when you WANT it to. Like I said only for testing reasons. I actually put it in my post about hitting 'H' key to reload it and said (don't do this unless for testing only reasons). I am not as familiar with LUA either way as I would like to be though, I mostly use Python with C/++
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Re: What are Benefits of Adding a Scripting Language to a Game?

Post by xx6heartless6xx »

Code: Select all

#include <iostream>
extern "C"
{
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
}

//The interpreter
lua_State *L;

int main()
{

    //Initialize Lua
    L = lua_open();

    //Open Lua Libraries
    luaL_openlibs( L );
    luaL_dofile(L, "test.lua");
    system("PAUSE");
    lua_close(L);
    return 0;
}
I recently opened up a Lua script from C++ which basically just outputted text onto the string but what I was wondering if you guys can give me some examples on what else you can do with Lua besides just outputting text.

In Falco's vid he did things like change the player's HP after an item was used, but cant that more easily done in C++? Anyways can you guys just give me some examples and some code to accompany it. Thanks
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: What are Benefits of Adding a Scripting Language to a Game?

Post by dandymcgee »

xx6heartless6xx wrote:In Falco's vid he did things like change the player's HP after an item was used, but cant that more easily done in C++?
Oh absolutely, but if you had read even half of the posts in this thread you would understand why storing such routines in Lua is much preferred for a large project (especially something as complicated as an RPG).
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
TheBuzzSaw
Chaos Rift Junior
Chaos Rift Junior
Posts: 310
Joined: Wed Dec 02, 2009 3:55 pm
Current Project: Paroxysm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: What are Benefits of Adding a Scripting Language to a Game?

Post by TheBuzzSaw »

If you are using C++, just #include lua.hpp instead. It does that silly extern wrapping for you (and includes all the files).
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: What are Benefits of Adding a Scripting Language to a Game?

Post by dandymcgee »

TheBuzzSaw wrote:If you are using C++, just #include lua.hpp instead. It does that silly extern wrapping for you (and includes all the files).
I didn't know that, cool tip.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply