Importing data from `.json` files - ItsDeltin/Overwatch-Script-To-Workshop GitHub Wiki

OSTW supports loading data from .json files. For example, imagine if this data.json file is in the same directory as main.ostw:

// data.json

{
  "NUM_BOTS": 4,
  "locations": [
    {"x": -12, "y": 0, "z": 42},
    {"x": 4, "y": 3, "z": 5}
  ]
}

main.ostw can access the data within data.json as follows:

# main.ostw

define NUM_BOTS = import("data.json").NUM_BOTS;
globalvar Vector[] location = import("data.json").locations;

Data Types

In the above example, keen-eyed readers may have noticed that the locations array had its structs of structure {x: number, y: number, z: number} automatically converted into Vector types. This automatic conversion applies to the following data types:

JSON OSTW Type
{"x": number, "y": number, "z": number} Vector
{"r": number, "g": number, "b": number, "a": number} CustomColor
{"color": "Blue"} Color
{"map": "King's Row"} Map
{"gamemode": "Flashpoint"} GameMode
{"button": "Primary Fire"} Button
{"team": "Team 1"} Team
{"hero": "Ana"} Hero