Hi everyone. I'm new to LOVE and am really liking it so far, but I'm trying to figure out text file input, which seems a bit different in LUA/LOVE than the languages I'm used to, like C++ and Gamemaker.
I'm planning on using text files as input and output for tiles/maps in my game. The text files will have a grid of integers that are each read and inserted into the cells of a table, which will then refer to quads with the appropriate sprite to show.
I've noticed that there are only two text input functions in LOVE: love.filesystem.lines and love.filesystem.read, neither of which are capable of reading individual characters at a time (I think). So I'm assuming that I will have to do some parsing to the line or block of text before sending it to the table.
At the moment I have some cheap code that just reads anything that isn't whitespace into the table. It works for now, and shows my idea works, but it's very limited and will have to be expanded before it is useful.
How do LOVE users normally implement this sort of text input? Should I use regular expressions (which I will have to learn) to parse the text before sending it to the table? Should I be using LUA's text file input functions instead? (I tried this and it worked but making it able to find the text files in the .love archive was a bit of a pain, and I've read that it is better to use LOVE's text file functions.) Or are there other functions or methods for doing this in LOVE?
Thanks ahead of time!
Text files input and parsing
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Text files input and parsing
There's a few different ways to parse input, and in my experience character-by-character parsing is usually more difficult than a pattern-based solution, but it's definitely possible. It seems you've completely missed File objects, and their associated methods? [wiki](File):read[/wiki] appears to be exactly what you're looking for. But, if you can spare the time, learning how to use patterns is probably well worth that time.
Re: Text files input and parsing
Ah, I knew I must have been missing something, thanks!
File:read should work pretty much exactly how I wanted, as I planned on eventually reading a couple bytes at a time, with one byte reserved for flags and whatnot.
Thanks again!
File:read should work pretty much exactly how I wanted, as I planned on eventually reading a couple bytes at a time, with one byte reserved for flags and whatnot.
Thanks again!
Who is online
Users browsing this forum: Google [Bot] and 1 guest