ObjectToJson(object, int)

From NWN Lexicon
Jump to: navigation, search
Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

Transforms the given object into a json structure.

json ObjectToJson(
    object oObject,
    int bSaveObjectState = FALSE
);


Parameters

oObject
The object to translate into json.
bSaveObjectState
specifies whether to include more detailed info in some cases; see below.


Description

Transforms the given object into a json structure.


Remarks

The json format is compatible with what niv's nimtools produce. Returns the null json type on errors, or if oObject is not serializable, with JsonGetError filled in. Supported object types: creature, item, trigger, placeable, door, waypoint, encounter, store, area (combined format) If bSaveObjectState is TRUE, local vars, effects, action queue, and transition info (triggers, doors) are saved out (except for Combined Area Format, which always has object state saved out).


Version

This function was added in 1.85.8193.31 of NWN:EE.


Example

// OnEnter script for an encounter, which reports a json serialization error with the encounter. Since 
// ObjectToJson() does not work on encoutners (see Known Issues below), try working around this with 
// TemplateToJson(), instead. 
//
void main()
{
    object oPC = GetEnteringObject();
    if( !GetIsPC( oPC ) )
        return;
 
    json jEnc = ObjectToJson( OBJECT_SELF );
    string sErr = JsonGetError( jEnc );
    string sDump = JsonDump( jEnc, 4 );
 
    SendMessageToPC( oPC, sDump );
    SendMessageToPC( oPC, sErr );
}

Known Issues

As of the 8193.34.1 patch, ObjectToJson() does not work for encounters. It uses some of the same functions as SqlBindObject() and StoreCampaignObject(), neither of which support encounters. For encounters, workarounds may be implemented that use TemplateToJson(), instead of ObjectToJson(). Thank you to Daz in the neverwintervault Discord for his aid in diagnosing this issue.


See Also

functions:

JSON Functions



author: Shadguy