A Team Fortress 2 VScript that provides functionality to save and load Squirrel tables to and from text files, allowing them to be stored across sessions.
Supports strings, integers, floats, bools, null and non-nested tables and arrays.
The SaveTable
function saves a table to a text file. The resulting file will appear in your .../tf/scriptdata/
folder.
SaveTable(table, file_name)
The LoadTable
function retrieves a table from a previously saved text file.
LoadTable(file_name)
Note
In both cases, the .txt
suffix is appended automatically.
Tip
You can add /
characters to the file_name
args to create subfolders.
IncludeScript("tableio")
my_table <- {
mystring = "Hello World!",
myinteger = 42,
myintegern = -42,
myfloat = 3.14,
myfloatn = -3.14,
mybool = true,
mynull = null,
myarray = [0, "Hello", true, null, 1.25],
mytable = {
key1 = 1,
key2 = "World!",
key3 = false,
key4 = null,
key5 = 2.5
}
}
# saving
SaveTable(my_table, "mytable")
# loading
my_loaded_table <- LoadTable("mytable")
# printing
foreach (key, val in my_loaded_table)
printl(format("> %s (%s) = %s", key, typeof val, "" + val))
IncludeScript("tableio")
my_table <- {
maxtime = 500,
maxcaps = 7,
allowstalemate = false
}
# saving
SaveTable(my_table, "mymap/config")
# loading
my_loaded_table <- LoadTable("mymap/config")
# printing
foreach (key, val in my_loaded_table)
printl(format("> %s (%s) = %s", key, typeof val, "" + val))
After running both examples, your .../tf/scriptdata/
folder should look like this:
.
├── mymap
│ └── config.txt
└── mytable.txt