I want to make a program that chooses a random monster from a list, give the user a list of usable weapons, and allows them to choose which weapon to use. I want to use external files to store data for the weapons instead of adding the tables in the Lua file itself. I have tried using Lua files to store the data as a table.
I have a file called sword.lua in the same folder as the program I want to access it's information. It contains
sword = {'sword', '10', '1', '100'}
I am trying to access the information using
wep = io.open("sword.lua", "r")
print(wep:read("*a"))
print(wep[1])
The first print returns all of the text in the file which is
"sword = {'sword', '10', '1', '100'}"
and the second is supposed to return the first item in the table. Every time I do this, I get a nil value from the second print. The file is being read, as indicated by the first print listing the text, but how do I make it read the file as a table that I can use in my program.
wepis) to return an item in a table described by a string stored in that file? - Nicol Bolas