[SOLVED] "Could not set write directory" even when t.identity is set

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
Aitch
Prole
Posts: 2
Joined: Mon Sep 02, 2019 7:07 pm

[SOLVED] "Could not set write directory" even when t.identity is set

Post by Aitch » Mon Sep 02, 2019 7:45 pm

I know similar questions have already been answered many times, so apologies if I could have found my answer in any of them. The solution for all the similar questions seemed to be either "don't set the save directory to something out of the default", or, "set t.identity in conf.lua", both of which do not cause this in my project.

Code: Select all

t.identity = "Puyo_Chains"
Save code: Binser is a table serializer

Code: Select all

print(love.filesystem.write("Puyo_Chains/" .. save_name .. ".txt", binser.serialize(grid.grid())))
I also tried saving this but it did not work either:

Code: Select all

print(love.filesystem.write("test.txt", "test"))
At first I thought it might be an issue with LOVE trying to save in a directory it did not have permission to, but I ran

Code: Select all

love.filesystem.getSaveDirectory( )
and it returned the /AppData/LOVE directory. (Now that I think of it, shouldn't it have returned /AppData/LOVE/Puyo_Chains?)

This was meant to just be a personal project so the controls aren't intuitive. I've included a controls file.
Attachments
controls.txt
(319 Bytes) Downloaded 31 times
PuyoMachine.love
(133.8 KiB) Downloaded 34 times
Last edited by Aitch on Mon Sep 02, 2019 9:30 pm, edited 1 time in total.

User avatar
Sasha264
Citizen
Posts: 60
Joined: Mon Sep 08, 2014 7:57 am

Re: "Could not set write directory" even when t.identity is set

Post by Sasha264 » Mon Sep 02, 2019 9:08 pm

Welcome! :awesome:
  • First: In the main.lua -> function init () you have this line: love.filesystem.setIdentity("")
    It is not supposed to be here, you already successfully set identity in the conf.lua
    After removing that line test save love.filesystem.write("test.txt", "test") will work.
  • Second: Before saving to the subfolder you need to make sure this folder exists:

    Code: Select all

    function save_file ()   
        if love.filesystem.getInfo("Puyo_Chains") == nil then
            love.filesystem.createDirectory("Puyo_Chains")
        end
        print(love.filesystem.write("Puyo_Chains/" .. save_name .. ".txt", binser.serialize(grid.grid())))
    end
    After that your real save will work.
  • Third: Maybe you don't need another one Puyo_Chains directory inside Puyo_Chains dyrectory inside love home.
    So your save function will be just:

    Code: Select all

    function save_file ()   
        print(love.filesystem.write(save_name .. ".txt", binser.serialize(grid.grid())))
    end

Aitch
Prole
Posts: 2
Joined: Mon Sep 02, 2019 7:07 pm

Re: "Could not set write directory" even when t.identity is set

Post by Aitch » Mon Sep 02, 2019 9:29 pm

Perfect! Thank you!

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests