[RESOLVE'D] Making files with a Level Editor

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
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

[RESOLVE'D] Making files with a Level Editor

Post by Connorses »

First, I'd like to let you know that I have made a level editor in the past, however, this editor only exported strings of lines of Lua code. The game had a loadLevel(number) function with a lot of if statements and the levels were basically hard-coded into the game. I would much rather save and load individual files, especially since I'm considering releasing the editor with the game.

What I'm looking for is a general solution for creating a new level data file and/or loading files. I looked at the filesystem commands on the Wiki and there was no obvious function for this, which means I would have to create a new text file by hand in the save directory if I want to start a new level. I don't mind doing this, but I know I've seen love2D games with level editors, so any help is appreciated!
Last edited by Connorses on Mon Aug 31, 2015 12:58 am, edited 1 time in total.
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Making files with a Level Editor

Post by veethree »

love.filesystem.newFile/write/read is pretty much the way to go about this.
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Making files with a Level Editor

Post by Connorses »

Thanks, I got it to save and load something today... I did not realize when reading about these commands that when you write to a nonexistent file it creates the file.

Now I just need to read up on the data format since I'm not especially familiar with this.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Making files with a Level Editor

Post by arampl »

May I ask why you decided to switch from Lua files to some other format?
I find it as the best text format for my own data files (GUI, levels, configuration, etc.).
And to load it all you need is simple "require".
Maybe harder for editor to generate such files but not that hard...
If you mean to use data files from languages other than Lua then Lua embedding is at hand.
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Making files with a Level Editor

Post by Connorses »

I would like to keep the level editor as part of the game so the end-user can mess with it, so it should be able to export and load custom levels. If I were to package the game as a .exe, could it still load levels saved as .lua files? I honestly don't know how that would work.

Also none of this really even matters yet. I obviously have no idea what I'm doing when I try to use love.filesystem.write because the files it generates are NOT text files.

Halp.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Making files with a Level Editor

Post by arampl »

Connorses wrote:I would like to keep the level editor as part of the game so the end-user can mess with it, so it should be able to export and load custom levels. If I were to package the game as a .exe, could it still load levels saved as .lua files? I honestly don't know how that would work.
It works for .love file on Linux (by requiring external file in user's save directory). I can't check .exe on Windows right now but big chances are will work too.
Connorses wrote:Also none of this really even matters yet. I obviously have no idea what I'm doing when I try to use love.filesystem.write because the files it generates are NOT text files.
Strange. This works:

Code: Select all

function love.load()
	data = "sdfsdfsdfsdfds"
	love.filesystem.write("test.txt", data, #data)
end
It creates text file.
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Making files with a Level Editor

Post by Connorses »

All right. I probably should have just posted my source code. I was going about this whole thing wrong. In fact, I learned quite a few things today.

For example, if you package your game as an executable or an app as per the instructions in the Wiki, it still contains ALL your source code. This is somewhat unorthodox if you're trying to make a game with the goal of selling it.

EDIT: I did find some info on how you could distribute a Love2D game with the compiled bytecode instead, but it's a thread from 2013, so at some point I'll have to figure out if their method is still compatible and/or whether I can recreate it. For now, I won't worry about all that. I'll just save levels as Lua code and I will figure out how to make the level editor export/load them later. Looks like it'll all work out though. :cool:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 82 guests