Skip to content

fayrghos/tf2-table-save-load

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Table Save/Load VScript

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.

Usage

Saving

The SaveTable function saves a table to a text file. The resulting file will appear in your .../tf/scriptdata/ folder.

SaveTable(table, file_name)

Loading

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.

Examples

General Usage

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))

Using Subfolders

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))

Result

After running both examples, your .../tf/scriptdata/ folder should look like this:

.
├── mymap
│   └── config.txt
└── mytable.txt

About

A TF2 script to preserve variables between sessions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published