Page 1 of 2

[SOLVED]Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 1:02 am
by ntpspe
Hello everyone.
I'm wanting to see if the conf.lua file is stored in the correct directory for editing, so:

I've used
config = love.filesystem.exists( "conf.lua" )
To check if it's there.
To display the result, I tried
love.graphics.print("Is the config there?: " .. config, 0, 80, 0)
But that's giving me an "Attempt to concatenate global variable "config" (boolean) error.

So how do I display the result of the check on screen?
Also, I've tried

Code: Select all

function checkconfig()
        isitthere = "Unchecked"
        config = love.filesystem.exists("conf.lua")
        if config == "True" Then
                  isitthere = "Yep"
        else
                  isitthere = "Nope"
        end
end
EDIT: and obviously after I then try to do love.graphics.print(isitthere) with the same result as before, an error...

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 2:26 am
by slime

Code: Select all

local config = love.filesystem.exists( "conf.lua" )
love.graphics.print("Is the config there?: " .. tostring(config), 0, 80, 0)
In your second example, you were trying to compare the result of love.filesystem.exists (a boolean) with a string (not a boolean, and the boolean true/false has a lowercase first letter as well).

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 2:54 am
by ntpspe
Ah I see using "tostring" worked perfectly and I can just do "love.graphics.print("blah"..tostring(config)" now :).

So am I correct in assuming by putting "tostring" makes the boolean variable a string variable for that print statement?

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 2:56 am
by slime
ntpspe wrote:Ah I see using "tostring" worked perfectly and I can just do "love.graphics.print("blah"..tostring(config)" now :).

So am I correct in assuming by putting "tostring" makes the boolean variable a string variable for that print statement?
Correct. You normally don't have to do that for numbers though, because it implicitly converts them to strings when you concatenate them together.

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 3:40 am
by ntpspe
Nice, thank you very much for your help :)

On another note (kinda going away from the topic, but still relevant)
Is there a way to get "love.filesystem.write" to write data to a specific line/column of the file?

For example, in the conf.lua there's " t.screen.fullscreen = false -- Enable fullscreen (boolean)"

So, basically I want

Code: Select all

function options()
        *blahblahimagesandtext*
        *button for fulscreen which toggles "clickedonfullscreen" to true/false*
        if clickedonfullscreen == "true" then
        love.filesystem.load(config.lua)
        love.filesystem.write(name, data, size)
        (ONLY ON LINE 8 COLUMN 12 - for example)
        end
end
If you understand my wording... I'm not too good with wording things on forums it seems >.<

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 7:11 am
by Robin
That last example code you gave is not even nearly correct Lua, but to answer your question: no.

It is considered Bad to write to conf.lua, but if you really want to do it, you need to write the entire file.

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 9:23 am
by bartbes
Nor will it work.

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 9:28 am
by Robin
bartbes wrote:Nor will it work.
Oh, right, since the write directory isn't set yet at the point that conf.lua is loaded.

Best to write to some other file, and loading that manually.

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 1:14 pm
by ntpspe
Robin wrote:That last example code you gave is not even nearly correct Lua.
You're very... critical.
If you get stuck, many friendly people are ready to help you at the forums
So much for that...

A. I'm using this as a learning project, so of course I'm gonna make mistakes and ask stupid questions, and that's what forums are for.
B. It was a random not-worded-properly example to just get my meaning across :/

Re: Displaying result for "love.filesystem.exists"

Posted: Mon Aug 08, 2011 1:33 pm
by Robin
ntpspe wrote:You're very... critical.
I spoke the truth. I realise now that it might come across as a bit harsh. For that, I apologise.
ntpspe wrote:A. I'm using this as a learning project, so of course I'm gonna make mistakes and ask stupid questions, and that's what forums are for.
True. However, that does not mean we are happy with a lot of "stupid" questions. The thing is, whether a question can really be stupid is debatable, but either way, you should learn from the answers to not only your questions, but the questions of others as well.
ntpspe wrote:B. It was a random not-worded-properly example to just get my meaning across :/
Thinking before acting is a good thing.

For a bit of context: we used to be a very small, very friendly community. We still are unusually friendly for an internet based community, but the recent influx of young virgins (new lovers) has caused us to be a bit more on edge. They generally don't think before they act, and that is really annoying.