And from the “Why Not Take Something Simple And Make It More Complex” department, you could also do something like this:
Instead of loading the words into different variables, load them into a table and access them using an index.
[lua]local words = { “The”, “cat”, “sat”, “on”, “the”, “mat” }[/lua]
So words[1] would equal “The”, words[2] would equal “cat”, and so on.
To print that string of words you can use a function like this:
[lua]local function displayWords(t)
for i = 1, #t do
print(t[i] … “\n”)
end
end[/lua]
You just pass in the table holding all your words and it prints them, each on a separate line.
By using a print function like that you could also create a function that puts a space between each word so it looks like a sentence, etc. Basically, you have “raw data” in the form of a table and can then manipulate it however you like.
And just for the fun of it, here’s an example that’s built off that idea. It uses two functions, one to put all the words of any given string into a table, and the second function to print them one per line.
[lua]local function loadWords(s)
local temp = {}
for word in string.gmatch(s, “[^%s]+”) do
table.insert(temp, word)
end
return temp
end
local function displayWords(t)
for i = 1, #t do
print(t[i] … “\n”)
end
end
local t = loadWords(“The cat sat on the mat”)
displayWords(t)[/lua]
I know your original question was already answered, but thought this might be helpful in other areas or for other folks looking for a similar solution.
Jay
[import]uid: 9440 topic_id: 24678 reply_id: 99999[/import]