How would I read a text file for level data?

I’m playing around making a DDR-esque game, and I need to send in text (or any other appropriate file) that contains a grid of the location of all the beats. Adding it directly to a script would seem inefficient.

Do you know any way to go about doing this?

For example, step mania files are stored like this
// — Arrows —
#NOTES:
dance-single:
Basic:
easy:
3:
:
1000
0000
1000
0000
0000
0000
0000
0000
,
0000
0000
0000
0000
1000
0000
0001
0000
,
0001
0000
0001
0000
0000
0000
0000
0000

…and more beats

If you control the data format the most obvious choice would be to add it as a Lua module that you can require from your script. That way you don’t have to do any parsing or anything like that. In your example you already have a predefined format so I’d look into adding the file(s) as custom resources in your game.project file. These files will then be included in your binary and you can read them using sys.load_resource().

3 Likes