Load and read textfile to use for building a 2d map

Godot Version

Godot_v4.2.1-stable_win64

Question

how do i parse a text file to use for map building on the fly so players can create and play custom maps the layout i would like is simple :
// map template:
//0 - walkable space or out of map
//1 - wall
//2 - movable object
//3 - stationary object
//4 - player
// first 2 lines are width and height of map
9
9
111110000
140010000
102210111
102010131
111011131
011000031
010001001
010001111
011111000

its easy to understand the map file.

how do i read each line so i know the “position” to spawn the correct object?

1 Like

It’ll be easier if you don’t include comments in the file. You can use FileAccess.get_line() to read the file line-by-line. Call it once for the width, once for the height, then write a loop and call it height number of times to get each row. Loop through the characters in the string get_line() returns to pull out each individual digit.

1 Like

this is a template map file so i know whats what. an actual map file wont have comments in it, thank you i didnt know about get_line.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.