Moving from Brain Damage to love

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Moving from Brain Damage to love

Post by Mr. Strange »

Hey love(ly) people.

I'm a professional game designer, and I've recenly been using lua to prototype new concepts. I started using Brain Damage.exe, which was really a great tool, but is sadly sort of dead now. It also had slightly ghetto draw support, and no audio component.

So I'm looking at love, and I largely like what I see. But a few things aren't quite making sense, and I'd appreciate some help bringing myself up to speed.

1 - I see that my print messages go to stdout - but is there no way I could view them on-the-fly? I feel like maybe I'm missing something obvious here. I use trace messages all the time when starting work on a new routine, and I'm not sure I could function efficiently without them. It's entirely possible that there is an obvious way to display stdout.txt on the fly - but I don't know one.

2 - Is there a way to create multiple windows? Brain Damage allowed me to define individual onmouseup functions for each active window, which was pretty cool.

3 - I'm not sure how to quickly iterate on my files - right now I edit the .lua in TextPad, and I've defined an external command to trigger which runs love $FileDir - which is working pretty well. How do other people do this reasonably?

4 - I write game save output to text files, and I wonder how I could force those into a directory other than the one where love.exe is running?

I'm really excited to join the love community - I just need to clear a few more hurdles!

-- Mr. Strange
User avatar
Jake
Prole
Posts: 27
Joined: Sun Jul 20, 2008 2:01 pm

Re: Moving from Brain Damage to love

Post by Jake »

Mr. Strange wrote:1 - I see that my print messages go to stdout - but is there no way I could view them on-the-fly? I feel like maybe I'm missing something obvious here. I use trace messages all the time when starting work on a new routine, and I'm not sure I could function efficiently without them. It's entirely possible that there is an obvious way to display stdout.txt on the fly - but I don't know one.
To be honest, my print messages never went to stdout. I think it's broken. Anyway, I use this code to produce a fake console output.

Code: Select all

local print_lines = {}
function print( ... )
	for k, v in pairs( {...} ) do
		table.insert( print_lines, tostring( v )  )
	end
end

function draw()
     --- at the end of your draw function
	local WIDTH = love.graphics.getWidth()
	-- draws the last 30 items of print_lines
	for i=1, math.min( 30, table.getn( print_lines ) ) do

		local n = math.max( table.getn( print_lines ) - 30, 0 ) + i

		love.graphics.setColor( 0,0,0,130 )
		love.graphics.draw( print_lines[ n ], (WIDTH-200) +1, i*15 +1 )
		
		love.graphics.setColor( 255,128,0,255 )
		love.graphics.draw( print_lines[ n ], WIDTH-200, i*15 )

	end
end
Mr. Strange wrote:2 - Is there a way to create multiple windows? Brain Damage allowed me to define individual onmouseup functions for each active window, which was pretty cool.
I don't think this is possible but I'll let someone else confirm.
Mr. Strange wrote:3 - I'm not sure how to quickly iterate on my files - right now I edit the .lua in TextPad, and I've defined an external command to trigger which runs love $FileDir - which is working pretty well. How do other people do this reasonably?
I'm not entirely sure what this means but maybe this will help.

Code: Select all

local list = love.filesystem.enumerate("subdir")
	for i=1, #list do
       		print("file: subdir/"..list[i])
	end
end
Mr. Strange wrote:4 - I write game save output to text files, and I wonder how I could force those into a directory other than the one where love.exe is running?
Not sure.
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Moving from Brain Damage to love

Post by Merkoth »

1 - It's not broken, that's just the way SDL behaves. This thing coded by Zeddy might help you with the text output issue and also give you some cool features. Also, you can call

Code: Select all

love.system.suspend()
and see some of your output in the built-in error screen.

2 - Not that I know of. Actually, I don't think SDL supports this.

3 - Define reasonably? Most IDEs do just that, launching the tools with a few parameters. I don't see anything wrong with your method.

4 - I'm afraid you can only dig further into that directory. For example, you could place your save file into /GameFolder/Sys/GTFO/NORLYGTFO/ultra-secret.lol Weird file extensions will confuse most Windows users and hopefully, they won't cheat your save file.

Keep in mind that those files you create will not always end up into the game directory. Under Linux, for example, they'll be stored into the user home/.love/ directory (a hidden one, btw).

Finally, you might also try to use Lua's filesystem functions, I'm not sure if the lövers deativated them though.

Welcome Mr. Strange, I hope this helps and happy coding!
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Moving from Brain Damage to love

Post by rude »

Yeah ... what they said.
  • On Windows, LÖVE is compiled with stdio redirect, which means that it writes the output to a file. For on-screen awesomeness, use Zeddy's console.
  • There's only one window.
  • Note that you must use love.filesystem for saves. The "io" and "os" library will be removed in the next version. If you're saving files next to the love.exe, then You're Doing It Wrong(tm).
Welcome, Mr. Strange!
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Moving from Brain Damage to love

Post by Mr. Strange »

Awesome. That's the sort of community support I've been missing!

I'll try that console thing - probably I'll hook it up to a key so I can toggle that information on and off - I'll probably also want to draw an alpha rectangle behind the output, to enhance readability.

--Mr. Strange
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Moving from Brain Damage to love

Post by rude »

It already has all that. ^^
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Moving from Brain Damage to love

Post by Mr. Strange »

rude wrote:Yeah ... what they said.
  • Note that you must use love.filesystem for saves. The "io" and "os" library will be removed in the next version. If you're saving files next to the love.exe, then You're Doing It Wrong(tm).
Welcome, Mr. Strange!
I look forward to adjusting my scripts, then. My first project was to "port" over a few thousand lines of script from Brain Damage -style to love-style. My io. calls were working, so I didn't bother adjusting them - I'll get on that!

--Mr. Strange
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Moving from Brain Damage to love

Post by Mr. Strange »

Ok, about the love.filesystem...

When reading a file, I typically read one line at a time, through the default behavior of io. I also like to force the result to a number, though that's not strictly necessary.

Code: Select all

file = io.open(filename, "r+")
	data = file:read("*number")
I haven't been able to reproduce this behavior with the love.filesystem structures, which is of the form:

Code: Select all

love.filesystem.read( file, count )
But maybe I can use a clever value for "count" which will give me this behavior?

--Mr. Strange
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Moving from Brain Damage to love

Post by rude »

Sorry, there's no love.filesystem.lines, nor is it possible to force a value into a number with "*number".

love.filesystem.lines will appear one day, but for now the best way of saving and loading stuff is actually writing Lua code:

Code: Select all

function save_highscore()
   local file = love.filesystem.newFile("highscore.lua", love.file_write)
   love.filesystem.open(file)
   love.filesystem.write(file, "highscore = { bob = 5, tom = 200, jane = 4000 }")
   love.filesystem.close(file)
end
Later, you can load the file with:

Code: Select all

love.filesystem.include("highscore.lua")
-- Table "highscore" is now available.
Post Reply

Who is online

Users browsing this forum: No registered users and 84 guests