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!
Standard Lua with love2D?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Standard Lua with love2D?
Hello, and welcome to the forum!
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: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 think this may help.CH3DD4R wrote:I want to make it an .exe, for one thing; .lua files aren't very nice for distributing.
LÖVE supports music!CH3DD4R wrote:Next, I would like to add some elements not possible in standard lua: specifically, music.
Again, I would have to see the code, but it shouldn't be too hard to port (especially at 125 lines).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?
Never heard of the "t" module before.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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- SneakySnake
- Citizen
- Posts: 94
- Joined: Fri May 31, 2013 2:01 pm
- Contact:
Re: Standard Lua with love2D?
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
Since you probably don't want to use the game loop LÖVE provides, override love.run(), and place your game there.
main.lua
conf.lua
Code: Select all
function love.conf(t)
t.window = nil
end
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?
Thanks for all the quick replies!
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?
Code: Select all
function love.conf(t)
t.window = nil
end
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?
- SneakySnake
- Citizen
- Posts: 94
- Joined: Fri May 31, 2013 2:01 pm
- Contact:
Re: Standard Lua with love2D?
You have to put this code in a file called conf.lua.CH3DD4R wrote:So, if I just put this at the beginning of my code, it'll stop the main window from running?Code: Select all
function love.conf(t) t.window = nil end
I'm not sure what you mean by that.CH3DD4R wrote:Does that mean I'd have to open up a debug window as well?
There is no standard, platform-independent way.CH3DD4R wrote:And is there, by any chance, a way to change text color?
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).
You could create a thread that polls whether the intro music has stopped, and when it stopped, it plays the loop.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?
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
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
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?
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?
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.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Standard Lua with love2D?
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.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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Standard Lua with love2D?
It doesn't.davisdude wrote:LÖVE uses Lua 5.2
Re: Standard Lua with love2D?
Oh, my bad. What does it use, then?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Google [Bot] and 2 guests