Page 1 of 2
Standard Lua with love2D?
Posted: Thu Mar 27, 2014 7:27 pm
by CH3DD4R
Ok, so I'm writing a text-based game in SciTE. It's only at 125 lines so far, but I would like to know if I need to convert my code into another format to do something special to this game: I want to make it an .exe, for one thing; .lua files aren't very nice for distributing. Next, I would like to add some elements not possible in standard lua: specifically, music.
Now, my question is this; is there any way to impost standard lua code into love2D, while maintaining it's format as a console-based game, whilst adding in music and such?
I've looked around, and it seems possibly the "t" module might help out, though I'm not sure how I'd do this.
Thanks in advance!
Re: Standard Lua with love2D?
Posted: Thu Mar 27, 2014 9:00 pm
by davisdude
Hello, and welcome to the forum!
CH3DD4R wrote:It's only at 125 lines so far, but I would like to know if I need to convert my code into another format to do something special to this game:
It depends, really. LÖVE uses Lua 5.2 and offers some other libraries, as well. You would have to attach your code in order to be sure, though.
CH3DD4R wrote:I want to make it an .exe, for one thing; .lua files aren't very nice for distributing.
I think
this may help.
CH3DD4R wrote:Next, I would like to add some elements not possible in standard lua: specifically, music.
LÖVE supports music!CH3DD4R wrote:Now, my question is this; is there any way to impost standard lua code into love2D, while maintaining it's format as a console-based game, whilst adding in music and such?
Again, I would have to see the code, but it shouldn't be too hard to port (especially at 125 lines).
CH3DD4R wrote:I've looked around, and it seems possibly the "t" module might help out, though I'm not sure how I'd do this.
Never heard of the "t" module before.
Re: Standard Lua with love2D?
Posted: Thu Mar 27, 2014 9:04 pm
by SneakySnake
Since LÖVE 0.9.0, you can set
t.window to
nil in
love.conf(t) to prevent LÖVE from creating a window.
conf.lua
Code: Select all
function love.conf(t)
t.window = nil
end
Since you probably don't want to use the game loop LÖVE provides, override
love.run(), and place your game there.
main.lua
Code: Select all
function love.run()
love.audio.newSource('music.ogg'):play()
print('Enter your name:')
name = io.read()
print('Thanks for playing, ' .. name)
end
Re: Standard Lua with love2D?
Posted: Thu Mar 27, 2014 11:27 pm
by CH3DD4R
Thanks for all the quick replies!
Code: Select all
function love.conf(t)
t.window = nil
end
So, if I just put this at the beginning of my code, it'll stop the main window from running? Does that mean I'd have to open up a debug window as well? And is there, by any chance, a way to change text color?
Another thing; On the Famitracker (the music software I'm using) forums, I was told the best way to properly loop the music infitely was to have the intro and loop in two separate files, play the intro, then play the loop and loop it infinitely. What wouls be the easiest way to go about this? to simply play the file, wait for the exact length of the file, then play the next one, and set it to loop?
Re: Standard Lua with love2D?
Posted: Fri Mar 28, 2014 1:27 am
by SneakySnake
CH3DD4R wrote:
Code: Select all
function love.conf(t)
t.window = nil
end
So, if I just put this at the beginning of my code, it'll stop the main window from running?
You have to put this code in a file called
conf.lua.
CH3DD4R wrote:Does that mean I'd have to open up a debug window as well?
I'm not sure what you mean by that.
CH3DD4R wrote:And is there, by any chance, a way to change text color?
There is no standard, platform-independent way.
If you want fancy stuff like that, you could port your game to use LÖVE's text rendering (i.e. create a window and use love.graphics.print).
CH3DD4R wrote:
Another thing; On the Famitracker (the music software I'm using) forums, I was told the best way to properly loop the music infitely was to have the intro and loop in two separate files, play the intro, then play the loop and loop it infinitely. What wouls be the easiest way to go about this?
You could create a thread that polls whether the intro music has stopped, and when it stopped, it plays the loop.
Here is an example I made up, I'm not sure how safe it is:
main.lua
Code: Select all
function love.run()
local intro = love.audio.newSource('intro.ogg')
local loop = love.audio.newSource('loop.ogg')
intro:play()
loop:setLooping(true)
local thread = love.thread.newThread('poll_and_play_loop.lua')
local channel = love.thread.getChannel('audio')
channel:push(intro)
channel:push(loop)
thread:start()
print('Enter your name:')
name = io.read()
print('Thanks for playing, ' .. name)
print(thread:getError())
end
poll_and_play_loop.lua
Code: Select all
require('love.timer')
require('love.audio')
local channel = love.thread.getChannel('audio')
local intro = channel:demand()
local loop = channel:demand()
while true do
if intro:isStopped() then
loop:play()
return
end
love.timer.sleep(0.1)
end
Just be reminded that although possible, LÖVE is not really intended to be used without a window.
The `t.window = nil` trick is intended for deferring the window creation, not preventing it altogether.
I am not sure that LÖVE can be safely and portably used this way. All I can say is that I have tested the programs I have presented here on my system (Arch Linux, x64), and they seem to work fine.
Perhaps the best way is to 'emulate' a text console using love.graphics.print. That way you can easily get fancy colored text and any other feature you might want to use.
Re: Standard Lua with love2D?
Posted: Fri Mar 28, 2014 2:57 am
by CH3DD4R
I might port it into a kind of "fake text" thing, but the colored text would've just been a cool feature. I will, however, port it if the t.window = nil trick turns out to be too unstable. And to answer you on the debug window thing, I had read somehwere in researching this possibility, and it said that a debug console could be attached to the game, and I thought perhaps the t.window = nil thing might just deal with the existence of a game window, so if you open up a console window along with it, it just becomes console. Thanks for the code, too.
Re: Standard Lua with love2D?
Posted: Fri Mar 28, 2014 9:11 am
by T-Bone
While something like this can be done using LÖVE, it feels like an overkill solution for a simpler problem. Lua files can be bundled into .exe if you know that you only want to target desktop Windows, and getting music to play shouldn't be too hard, there should be Lua bindings to several music libraries.
Re: Standard Lua with love2D?
Posted: Fri Mar 28, 2014 3:34 pm
by CH3DD4R
T-Bone wrote:While something like this can be done using LÖVE, it feels like an overkill solution for a simpler problem. Lua files can be bundled into .exe if you know that you only want to target desktop Windows, and getting music to play shouldn't be too hard, there should be Lua bindings to several music libraries.
I've looked into all those, and I've felt that, for some reason, it'd be a bit better to do this. I could never get the lua file-saving to work well for me; love2D seems to solve that problem for me, a little bit.
Re: Standard Lua with love2D?
Posted: Sat Mar 29, 2014 10:59 am
by bartbes
davisdude wrote:LÖVE uses Lua 5.2
It doesn't.
Re: Standard Lua with love2D?
Posted: Sat Mar 29, 2014 2:17 pm
by davisdude
Oh, my bad. What does it use, then?