JsonToObject(json, location, 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.

Deserializes the game object described in jObject.

object JsonToObject(
    json jObject,
    location locLocation,
    object oOwner = OBJECT_INVALID,
    int bLoadObjectState = FALSE
);


Parameters

jObject
object to deserialize from json.
locLocation
specifies the location where the object is created.
oOwner
object owner. If valid, for valid use cases, the object is placed in owner's inventory and locLocation is ignored.
bLoadObjectState
specifies whether to include more detailed info in some cases; see below.


Description

Deserializes the game object described in jObject.

Returns OBJECT_INVALID on errors.

Supported object types: creature, item, trigger, placeable, door, waypoint, encounter, store, area (combined format). For areas, locLocation is ignored.

If bLoadObjectState is TRUE, local vars, effects, action queue, and transition info (triggers, doors) are read in.


Remarks

Use TemplateToJson to easily initially generate the JSON needed, else you'll be rolling your own by hand - there is no loadable JSON datatype at the moment.

Once generated make tweaks and changes then use this function to spawn it into the world.


Version

This function was added in 1.85.8193.31 of NWN:EE.


Example

Example will take a placeable of resref "plc_resref" (invalid - replace with your own) and alter the appearance to line ID 33, a Ballista, then spawn it.

#include "nw_inc_gff"
void main()
{
    // Generate JSON from resref template
    json jPlaceable = TemplateToJson("plc_resref", RESTYPE_UTP);
 
    // Change to appearance 390
    jPlaceable = GffReplaceDword(jPlaceable, "Appearance", 33);
 
    // Spawn
    JsonToObject(jPlaceable, GetLocation(OBJECT_SELF));
}

See Also

functions:

JSON Functions