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/++GyroVorbis wrote: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.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.
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).
What are Benefits of Adding a Scripting Language to a Game?
Moderator: Coders of Rage
- MadPumpkin
- 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?
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
For God so loved the world that he blessed the thugs with rock
- xx6heartless6xx
- 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?
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;
}
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
- dandymcgee
- 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?
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).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++?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- TheBuzzSaw
- 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?
If you are using C++, just #include lua.hpp instead. It does that silly extern wrapping for you (and includes all the files).
- dandymcgee
- 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?
I didn't know that, cool tip.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).
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!