Pattern Matching Question

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
Candall
Prole
Posts: 19
Joined: Sat Oct 31, 2009 1:09 pm

Pattern Matching Question

Post by Candall »

Hi, guys.

I have a function that needs to load a bunch of values from lines in a file. Here's what I have so far:

Code: Select all

if filepos=="tiles" then
	row=row+1
	column=0
	tilelist[row]={}
	for word in string.gfind(line, "[%d]+") do
		column=column+1
		tilelist[row][column]=word
	end
end
Basically, this loads a table of rows and columns (to be used in a simplistic tile map engine).

The problem is the third from the last line, which loads the actual data into the table index. Everything else works perfectly. I know that if I have fourteen lines with 25 numbers each in the text file, I'll get a table filled with 14*25 values. If I simply susbstitute the "word" with a "1," the tile with the index of "1" loads.

So my question is... since I can count the number of tile references in my file, what do I need to change to make it take the actual reference and insert it into the file?
Candall
Prole
Posts: 19
Joined: Sat Oct 31, 2009 1:09 pm

Re: Pattern Matching Question

Post by Candall »

Heh, never mind. I figured it out.

In case any of you ever find yourselves in a similar position, the "[$d+]" needs to be changed to "$w+". Then, assign the table index as tonumber(word).
Post Reply

Who is online

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