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 .
onper
Prole
Posts: 3 Joined: Tue Aug 14, 2012 9:39 am
Post
by onper » Tue Aug 14, 2012 9:56 am
Hi!
I have this small problem when reading the lines of a text document using the following code.
Code: Select all
for line in love.filesystem.lines("questions.txt") do
if line ~= "" or line ~= "a" then
table.insert(canvas_questions, line)
end
print(line) -- for debugging purposes
end
The text file, as an example
The problem is that the code adds the line to the table even if it contains an empty space or an a. I have a feeling that this could be caused by the "new line" unicode, but I haven't made any progress there, which I'm asking you to help me.
I know I can probably solve this by checking the line with a string function to see it's first character matches a etc.
Thank you for the help!
Nixola
Inner party member
Posts: 1949 Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy
Post
by Nixola » Tue Aug 14, 2012 10:35 am
Try
Code: Select all
if line ~= "\n" or line ~= "a\n" then
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Tue Aug 14, 2012 10:41 am
No.
Replace or by and .
If you do "a ~= b or a ~= c" (with b ~= c) then whatever the case, it always returns true. Think about it.
Nixola
Inner party member
Posts: 1949 Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy
Post
by Nixola » Tue Aug 14, 2012 10:44 am
...Right. Thanks, even if I'm not the OP
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
onper
Prole
Posts: 3 Joined: Tue Aug 14, 2012 9:39 am
Post
by onper » Tue Aug 14, 2012 10:59 am
Thanks for getting back with solutions so quickly!
It worked perfectly fine with replacing or with and, now I kind of feel stupid about that mistake...
onper
Prole
Posts: 3 Joined: Tue Aug 14, 2012 9:39 am
Post
by onper » Tue Aug 14, 2012 11:35 am
Another question while I'm at it
I'm a little experienced with Java and when you're increasing an int, you can type
While in lua you have to do
is there some way to do it in lua like the java example?
Petunien
Party member
Posts: 191 Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)
Post
by Petunien » Tue Aug 14, 2012 12:51 pm
As far as I know there's no possibility to increment a number like in java or elsewhere.
You have to do:
"Docendo discimus" - Lucius Annaeus Seneca
Roland_Yonaba
Inner party member
Posts: 1563 Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:
Post
by Roland_Yonaba » Tue Aug 14, 2012 4:37 pm
Well, it is not possible to do such a thing in Lua, by default.
But, you may use
Meta ...
Users browsing this forum: Ahrefs [Bot] , Amazon [Bot] , Bing [Bot] , Google [Bot] and 11 guests