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!
[RESOLVE'D] Making files with a Level Editor
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[RESOLVE'D] Making files with a Level Editor
Last edited by Connorses on Mon Aug 31, 2015 12:58 am, edited 1 time in total.
Re: Making files with a Level Editor
love.filesystem.newFile/write/read is pretty much the way to go about this.
Re: Making files with a Level Editor
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.
Now I just need to read up on the data format since I'm not especially familiar with this.
Re: Making files with a Level Editor
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.
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.
Re: Making files with a Level Editor
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.
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.
Re: Making files with a Level Editor
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: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.
Strange. This works: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.
Code: Select all
function love.load()
data = "sdfsdfsdfsdfds"
love.filesystem.write("test.txt", data, #data)
end
Re: Making files with a Level Editor
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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 82 guests