Skip to content

Test if Campaign Json exists

Just wondering what function to use to test the existence of a campaign json. If there isn't one you are looking for does it return an error? Can't seem to find it anywhere. I can check for a null value IN the json but not sure that would determine whether or not the campaign json has already been created.

P.S. Very new to json and trying to figure this out. I've figured out how to make arrays and object in java script but trying to use this in NWScript...It's giving me a headache. Are there any tutorials yet that I just can't find?

Comments

  • ForSeriousForSerious Member Posts: 446
    One of the nuances of JavaScript is to not care so much how defined things are.
    I want my JSON to have a value assigned to frog. JSON.frog = "King Frog";
    Oh wait, frog should be a number. JSON.frog = 2. Done.
    It's common to read in values from the JSON and then check if those are even defined.

    So, we can't really do things that relaxed in NWNScript.
    JsonGetError looks like it will get you what you want.
    If it comes back with a string, then your json is not defined. (I haven't tested it, but that's the only thing that makes sense to me.)
    Something like:
    string sError = JsonGetError(GetCampaignJson("Hero", "Heroing"));
        if(sError != "")
        {
            //Go ahead and use the object.
        }
    
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    ForSerious wrote: »
    One of the nuances of JavaScript is to not care so much how defined things are.
    I want my JSON to have a value assigned to frog. JSON.frog = "King Frog";
    Oh wait, frog should be a number. JSON.frog = 2. Done.
    It's common to read in values from the JSON and then check if those are even defined.

    So, we can't really do things that relaxed in NWNScript.
    JsonGetError looks like it will get you what you want.
    If it comes back with a string, then your json is not defined. (I haven't tested it, but that's the only thing that makes sense to me.)
    Something like:
    string sError = JsonGetError(GetCampaignJson("Hero", "Heroing"));
        if(sError != "")
        {
            //Go ahead and use the object.
        }
    

    Yeah I think that might have been it. Thank you @ForSerious . One hurdle jumped. I'll keep chugging along trying to get this and test that out. Eventually I would like to figure out the NUI stuff but I need to get this json part down first.
  • DazDaz Member Posts: 125
    You can use
    // Describes the type of the given json value.
    // Returns JSON_TYPE_NULL if the value is empty.
    int JsonGetType(json jValue)

    to check if something exists, it'll return JSON_TYPE_NULL if it does not.
Sign In or Register to comment.