Lua question - loading multiple scripts
Moderator: Coders of Rage
- Moosader
- Game Developer
- Posts: 1081
- Joined: Wed May 07, 2008 12:29 am
- Current Project: Find out at: http://www.youtube.com/coderrach
- Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
- Programming Language of Choice: C++
- Location: Kansas City
- Contact:
Lua question - loading multiple scripts
I'm playing around with Lua (in C++) a little bit finally, and writing a basic text adventure with it. Anyways, I want to separate different things like the map table and functions from the item table and functions, but I can't really find anything on how to have multiple scripts open.
Or am I overcomplicating it? I just want to call different functions from different .lua files.
Or am I overcomplicating it? I just want to call different functions from different .lua files.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Lua question - loading multiple scripts
I don't think that I really understand what you want (because there are lots of ways to do it).
You can either include the lua scripts with the desired functions inside of the lua script that you have open. Or you can create another instance of the Lua interpreter, and load the script there. OR, you can break the existing VM instance into multiple threads/coroutines, each with their own Lua script loaded.
You can either include the lua scripts with the desired functions inside of the lua script that you have open. Or you can create another instance of the Lua interpreter, and load the script there. OR, you can break the existing VM instance into multiple threads/coroutines, each with their own Lua script loaded.
- Moosader
- Game Developer
- Posts: 1081
- Joined: Wed May 07, 2008 12:29 am
- Current Project: Find out at: http://www.youtube.com/coderrach
- Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
- Programming Language of Choice: C++
- Location: Kansas City
- Contact:
Re: Lua question - loading multiple scripts
I mainly just want to have multiple .lua files for different types of data types and functions (like how we separate classes into separate .h files).
Basically, so the lua script doesn't turn out like Shattered Wrath's long-ass file:
http://www.moosader.com/misc/combatsystem.lua
I thought I had recalled someone telling me that there was a way to store all that in separate files.
Basically, so the lua script doesn't turn out like Shattered Wrath's long-ass file:
http://www.moosader.com/misc/combatsystem.lua
I thought I had recalled someone telling me that there was a way to store all that in separate files.
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Lua question - loading multiple scripts
I know this isn't helpful, at all, but
"TEXT::DON’T COME ANY CLOSER!, he says, brandishing an office chair.",
pretty funny to read through your dialogue haha
"TEXT::DON’T COME ANY CLOSER!, he says, brandishing an office chair.",
pretty funny to read through your dialogue haha
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- Moosader
- Game Developer
- Posts: 1081
- Joined: Wed May 07, 2008 12:29 am
- Current Project: Find out at: http://www.youtube.com/coderrach
- Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
- Programming Language of Choice: C++
- Location: Kansas City
- Contact:
Re: Lua question - loading multiple scripts
Oh, yeah. That script file is from a group project I worked on last Spring. Someone else did the scripting and story, so I was like "wtf" when I first read that. XD;short wrote:I know this isn't helpful, at all, but
"TEXT::DON’T COME ANY CLOSER!, he says, brandishing an office chair.",
pretty funny to read through your dialogue haha
Re: Lua question - loading multiple scripts
If you haven't already figured it out, you can use: dofile("file.lua") to include another script.Moosader wrote:I'm playing around with Lua (in C++) a little bit finally, and writing a basic text adventure with it. Anyways, I want to separate different things like the map table and functions from the item table and functions, but I can't really find anything on how to have multiple scripts open.
Or am I overcomplicating it? I just want to call different functions from different .lua files.
Here's a reference.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Lua question - loading multiple scripts
I guess what you want is probably just the equivalent of #include, which is dofile() as andrew said. But I must say, Shattered Wrath looks ridiculously long as a result of poor design, rather than just not being able to separate things into files.
That's got to be at least three to five times longer than the longest script in ES. Does your engine handle anything other than just rendering/collision? You probably would have been better off just writing the entire thing in Lua and saying screw C++, if Lua is going to be doing everything.
That's got to be at least three to five times longer than the longest script in ES. Does your engine handle anything other than just rendering/collision? You probably would have been better off just writing the entire thing in Lua and saying screw C++, if Lua is going to be doing everything.
- Moosader
- Game Developer
- Posts: 1081
- Joined: Wed May 07, 2008 12:29 am
- Current Project: Find out at: http://www.youtube.com/coderrach
- Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
- Programming Language of Choice: C++
- Location: Kansas City
- Contact:
Re: Lua question - loading multiple scripts
Hmm, I could do everything in Lua, but I kinda wanted to get familiar using it with C++. It's just going to be a basic text adventure, tho, with moving, battles, items, and such.
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: Lua question - loading multiple scripts
use require() it's pretty much #include
main.lua
somescript.luaProgramming in lua book wrote: Lua offers a higher-level function to load and run libraries, called require. Roughly, require does the same job as dofile, but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work. Because of these features, require is the preferred function in Lua for loading libraries.
Code: Select all
--over simplified but whatever
GlobalVar = 20 --OH NOEZ
function SomeFunction(Str)
print("Got string =>", Str)
end
Code: Select all
require("somescipt.lua")
SomeFunction("This is a String")
print(GlobalVar)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.