Modding Help [solved] Syntax problem with array patching for sprinkler object patch.

Discussion in 'Starbound Modding' started by NerArth, Feb 10, 2017.

  1. NerArth

    NerArth Pangalactic Porcupine

    Last night I tried doing a sprinkler.object.patch but it refused to work because the game would be unable to parse the JSON. I've gone for an alternative method, but I would still like to figure this out...

    Here's a sample I just re-did now of what I was doing before:

    sprinkler.object.patch

    [
    {
    "op":"add",
    "path":"/learnBlueprintsOnPickup",
    "value":"sprinkler_n_advanced"
    }
    ]

    When I tested this patch on an online parser, it works... (once I remove the comments found in the original sprinkler.object in the original data for the parser)

    The only thing I can think of is that the value maybe should be expressed differently.

    The only errors that come from the log file:

    [14:48:46.413] [Error] Could not instantiate item '[sprinkler, 1, {}]'. (JsonException) Improper conversion to JsonArray from string
    [14:48:46.524] [Error] Could not instantiate item '[sprinkler, 1, {}]'. (JsonException) Improper conversion to JsonArray from string

    Edit 2: Changed title to reflect the fact that the issue has been figured out.
     
    Last edited: Feb 10, 2017
  2. Inf_Wolf14

    Inf_Wolf14 Parsec Taste Tester

    You are attempting to patch a string value to an element that is an array.

    You have to reference the index of an array you are patching to. In JSON, a hyphen in the path will append data to the next available index of an array, which is what you would use in this case.

    Try this:
    Code:
    [
      {
        "op" : "add",
        "path" : "/learnBlueprintsOnPickup/-",  <----- Notice I am appending your string to an index value
        "value" : "sprinkler_n_advanced"
      }
    ]
    
     
    bk3k likes this.
  3. NerArth

    NerArth Pangalactic Porcupine

    Thank you for the reply; Could swear I tried that last night. (I looked through the patching guide here in the forums several times last night too.)

    With the path edit you suggested, this is seemingly what happens now.

    Code:
    [15:36:48.327] [Error] Could not apply patch from file /objects/generic/sprinkler/sprinkler.object.patch in source: ..\mods\Ners_ModdedFarming.  Caused by: (JsonPatchException) Could not apply patch to base. (JsonPatchException) Could not apply operation to base. (TraversalException) No such key 'learnBlueprintsOnPickup' in pathApply("/learnBlueprintsOnPickup/-")
    I'm guessing that now the problem is that the path doesn't exist and so the path has to be added first somehow? I thought that shouldn't be necessary, and that it would simply create the path...?
     
  4. Inf_Wolf14

    Inf_Wolf14 Parsec Taste Tester

    Oh, okay its clearer what you are attempting now.

    What I posted (and thought you were doing) is for appending to the existing array, what you had was mostly right. But the same logic error occurs as I said: You were adding a string to an element expecting an array of strings.

    Try this one:
    Code:
    [
      {
        "op" : "add",
        "path" : "/learnBlueprintsOnPickup",
        "value" : [ "sprinkler_n_advanced" ]
      }
    ]
    
     
    Cyel likes this.
  5. NerArth

    NerArth Pangalactic Porcupine

    I'm really not used to the syntax yet, but I really don't know how I struggled so much last night.

    Thank you for the help, that seems to have done it. I've marked your reply as "best answer".
     
    Inf_Wolf14 likes this.

Share This Page