json
The json data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This is only available in NWN:EE.
You don't write the JSON directly as such (as a string for instance), but you can build it in NWN using the in built functions. You may also convert an object to JSON or import a JSON file built externally and added to a SQLite DB. You can also save and load the JSON from Sql using nwscript.
You can dump the JSON you create to the log if you want to get it out of the game using WriteTimestampedLogEntry(JsonDump(jValue)). Alternatives to this are dumping in into an sqlite DB and reading it from there and printing it using SpeakString for the smallest of dumps and typing it out again.
There are a number of JSON Functions that can help manipulate, test, and use json.
With SQLite the JSON library is built in.
Example
int GetCreatureSoundset(object oCreature)
{
if(GetObjectType(oCreature) != OBJECT_TYPE_CREATURE) return -1;
// Convert to JSON
json jGet = ObjectToJson(oCreature);
// Retrieve the key
jGet = JsonObjectGet(jGet, "SoundSetFile");
if(JsonGetType(jGet) == JSON_TYPE_NULL)
{
SpeakString("JsonObjectGet error 1: " + JsonGetError(jGet));
return -1;
}
// Retrieve the value
jGet = JsonObjectGet(jGet, "value");
if(JsonGetType(jGet) != JSON_TYPE_INTEGER)
{
SpeakString("JsonObjectGet error 2: " + JsonGetError(jGet));
return -1;
}
return JsonGetInt(jGet);
}
See Also
functions: |