EDITED: In order to find a specific char, use the string class, which you can use to find spaces with .match() and in turn allow you find beginning and end of words<br><br><br>Hello! I can answer this question for you, although I have not tested, this is generally it<br><br>var file_path = 'res://file.txt' #have the file path<br><br>
var file = File.new() #new file class on which you will call file class methods
file.open(file_path,file.READ) #the file is now opened in the background<br><br>var line_counter = 0 #an integer to count the lines<br><br>while !eof_reached(): #this loops through each line until the file end is reached<br>line_counter+=1 #as its doing so, before getting the next line, it adds a counter<br>file.get_line() #sets the file read cursor to the next line<br><br>file.seek(0) #this is now outside of the former loop. after the loop, reset the cursor position<br><br><br>var random_last_line = randi() % line_counter # integer generated that is equal to line 0, to a random line counted<br><br><br>var store_line = '' #the varialbe that will store the line is an empty string for now<br><br><br>for i in range(0,random_last_line):<br>store_line = file.get_line() #randomly get a line, which is now set to store_line string variable<br><br><br><br><br><br>