string:sub(x, y) is exactly the same as string.sub(string, x, y)
In case you don't know what string.sub does, it gets a section of the string from index "x" to index "y", 1 to length of string or -1 to -length of string, so
string:sub(1, -1) will get the whole string but string:sub(2, -2) will cut off the first and last letters of the string, so
string:sub(1, 4) will get the first 4 letters (from 1 to 4) so if it was:
"Hello World" and you did:
string:sub(1, 4) you would get "Hell" in return, if you did string:sub(2, -2) you would get "ello Worl", the string you are using the function on does not have the changes applied to it but instead a new string is returned with the changes done.
to add a line to the word at a random point amongst the characters then (if you want the word to be random do this):
local words = {"Hello", "World", "Random", "Word", "", "", "", "", ""} -- A table containing all of the words that could get randomly put in to a line
local chars = "!#£$%&'[]{}()/><~"..'"' --string containing all possible random character
local l = 12 --length of each line
local h = 17 --amount of lines
local offset = {1,1} --offset of x,y cursor pos
for y=1,17 do
local line = ""
for i=1,l do
local n = math.random(string.len(chars)) --get a random character index from the string "chars"
line = line..chars:sub(n,n) -- put the random character on the end of the line
end
local n = math.random(string.len(line)) --get a random index of the string "line"
local str = {line:sub(1, n-1), line:sub(n, -1)} --split the string "line" before and after this index
line = str[1]..(words[math.random(#words)])..[2] --put a random word either side of this n
term.setCursorPos(offset[1], offset[2]+(y-1))
term.write(line)
end
NOTE:
this won't stick to your string length any more, there would be more code needed if you want that :(/>/>