How to display one line of text from a text file as a wall in a game, bestly, which are best known techniques?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gooodot

I would like to use simple line based .txt files as data source for games. Each line of text I would like to represent as a wall, for example. What would be best way of doing this? Any hints or similar examples, games, demos? Thanks in advance.

Example case: .txt file with 100 lines, in game I have 100 walls, each line should be randomly on some wall. When touching this wall, something could happen to the text content for example. e.g. it could be translated to another language. Imagine vocabulary learning games, or anything you could do with text.

Second question, which is not in the title. How you would do same with 100 .svg files, rather than 100 lines of text? 100 .svg files, randomly placed on 100 walls in a game. A game development could be very quick then, just design your 100 svg files, and convert it quickly to a ‘wall based game’. Imagine this could be something like an art gallery where every ‘art piece’ is represented on one wall. I would prefer .svg over .png, here.

:bust_in_silhouette: Reply From: sparkart

Before anything else, you can load the lines from file into an array, and call array.shuffle() to randomize the order:

func load_file(filename):
  var result = {}
  var f =
  var index = 1
  while not f.eof_reached():
    var line = f.get_line()
    result[str(index)] = line
    index += 1

Then, in the ready function of your wall object, it should read the next element of your array.

text = result[GLOBAL.index]
GLOBAL.index += 1