Hello everyone, here's my current game!
https://dl.dropboxusercontent.com/u/218 ... eFrog.love
I would like to add a 'replay' function to my game. So basically, at the end of each round, it would save the entire keybuffer table for that round to a file. Then, I would have a 'replay' which would load the saved file, and then play it back.
Technically, the only part I don't know how to do is to read and write the file. I think the default love2d filesystem folder is in some crazy place where I need administrator privileges, and I don't know how to make it read/write from my base directory. What is a good way to do what I want to do here?
Recommended way to read from and write to files?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Recommended way to read from and write to files?
What leads you to believe that?garcia1000 wrote:I think the default love2d filesystem folder is in some crazy place where I need administrator privileges, and I don't know how to make it read/write from my base directory.
https://www.love2d.org/wiki/love.filesystem.write
https://www.love2d.org/wiki/love.filesystem.read
https://www.love2d.org/wiki/love.filesystem.load
you may want to use an existing serialization library like Ser or serpent for example (there are tons and tons of these)
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Recommended way to read from and write to files?
Thank you, I will try those and I'll come back if I can't get it to work.
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Recommended way to read from and write to files?
I can't get this to work, what am I doing wrong?
https://dl.dropboxusercontent.com/u/218 ... eFrog.love
I have this in conf.lua:
Then, I have this in main.lua:
Neither of those writes "Hello" to Test.txt in the "files" folder.
I have also tried useing love.filesystem.setIdentity to set the path, but that doesn't work either.
https://dl.dropboxusercontent.com/u/218 ... eFrog.love
I have this in conf.lua:
Code: Select all
function love.conf(t)
t.identity = "files"
end
Code: Select all
love.filesystem.write("files/Test.txt", "Hello", all)
love.filesystem.write("Test.txt", "Hello", all)
I have also tried useing love.filesystem.setIdentity to set the path, but that doesn't work either.
Re: Recommended way to read from and write to files?
If you want to write *all* data then:
P.S. "files" folder resides in the user's home directory like "home/<user's name>/.local/share/love/files" on Linux.
Code: Select all
love.filesystem.write("Test.txt", "Hello")
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Recommended way to read from and write to files?
Thanks, that is my problem I think. I'm using a Windows machine and I think the 'home' directory needs administrator privileges to write, or something. I can't control how it acts on different machines.
Can I set the directory to be the same path where main.lua is?
Can I set the directory to be the same path where main.lua is?
Re: Recommended way to read from and write to files?
How can you add a file in the archive (.love file)? It's nearly imposibble. If it can, how can you add a file on running file archive? So the answer is no. But if you're talking about another main.lua, which path are you talking about? Source base or save directory?garcia1000 wrote:Can I set the directory to be the same path where main.lua is?
Re: Recommended way to read from and write to files?
On windows the data is in APPDATA: https://www.love2d.org/wiki/love.filesystem (read the text at the beginning)garcia1000 wrote:Thanks, that is my problem I think. I'm using a Windows machine and I think the 'home' directory needs administrator privileges to write, or something. I can't control how it acts on different machines.
Can I set the directory to be the same path where main.lua is?
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Recommended way to read from and write to files?
Ok, thanks, I see now!
I was trying to set a config.lua file in the same directory as main.lua. But that's impossible. Instead, it needs to create a config.lua file in the Appdata directory. Thanks.
I was trying to set a config.lua file in the same directory as main.lua. But that's impossible. Instead, it needs to create a config.lua file in the Appdata directory. Thanks.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests