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

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.
User avatar
ntpspe
Prole
Posts: 31
Joined: Sun Aug 07, 2011 6:19 pm

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

Post by ntpspe » Mon Aug 08, 2011 1:02 am

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...
Last edited by ntpspe on Mon Aug 08, 2011 1:32 pm, edited 1 time in total.

User avatar
slime
Solid Snayke
Posts: 2904
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post by slime » Mon Aug 08, 2011 2:26 am

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).

User avatar
ntpspe
Prole
Posts: 31
Joined: Sun Aug 07, 2011 6:19 pm

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

Post by ntpspe » Mon Aug 08, 2011 2:54 am

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?

User avatar
slime
Solid Snayke
Posts: 2904
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post by slime » Mon Aug 08, 2011 2:56 am

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.

User avatar
ntpspe
Prole
Posts: 31
Joined: Sun Aug 07, 2011 6:19 pm

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

Post by ntpspe » Mon Aug 08, 2011 3:40 am

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 >.<

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Mon Aug 08, 2011 7:11 am

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.
Help us help you: attach a .love.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes » Mon Aug 08, 2011 9:23 am

Nor will it work.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Mon Aug 08, 2011 9:28 am

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.
Help us help you: attach a .love.

User avatar
ntpspe
Prole
Posts: 31
Joined: Sun Aug 07, 2011 6:19 pm

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

Post by ntpspe » Mon Aug 08, 2011 1:14 pm

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 :/

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Mon Aug 08, 2011 1:33 pm

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.
Help us help you: attach a .love.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 16 guests