Tutorial Basic Patching Now With Path Guide [v1.9]

Discussion in 'Starbound Modding' started by The | Suit, Sep 19, 2014.

  1. Mara1681

    Mara1681 Phantasmal Quasar

    I read it, but I didn't understand it. Now with your another example of patch, I get it... :) Thx :)
     
  2. The | Suit

    The | Suit Agent S. Forum Moderator

    Can you tell me what was hard to understand? That way I can make it easier for other people in the future
     
  3. Mara1681

    Mara1681 Phantasmal Quasar

    I thought that the patch means something like patch to some file.
    So if I want to make some object, then I will make /defaultBlueprints/tier1/0 directory with testobject.item file in my mod folder...
    That's why I didn't use patch in my code example... :D
    Get it? It's little bit hard for me to explain it in English language.
     
  4. The | Suit

    The | Suit Agent S. Forum Moderator

    Ah.... well one good way to help the community is to rewrite the tutorial in your own language. So it will help those from your place understand easier, you can make it a word document attachment, as they are not to fond of other language posts.
     
  5. Dunto

    Dunto Guest

    Non-English posts are fine as long as there is an English translation in the same post. You could always shove the translated version into a spoiler in the main tutorial or something.
     
    The | Suit likes this.
  6. Mara1681

    Mara1681 Phantasmal Quasar

    I can translate it to the Czech language, but I'm not sure, if it is necessary...
    Czech modding community for Starbound is very small.
    Just tell me and I will translate it for you... :)
     
  7. The | Suit

    The | Suit Agent S. Forum Moderator

    It is totally up to you.
    By the way just in case you didn't know about this site
    http://www.playstarbound.cz/

    Its the Czeh starbound community
     
  8. Mara1681

    Mara1681 Phantasmal Quasar

    Wow, I didn't know about this site... :DD
     
    The | Suit likes this.
  9. AstralGhost

    AstralGhost Pangalactic Porcupine

    Just for future reference:
    I reviewed the documentation and tested this out pretty thoroughly. I can confirm this.

    You can only add/modify an entire array within square brackets [ and ], or a single value of a key-value pair ("key" : value).

    Even though stuff within curly braces { and } is treated like an array, it will not allow you to modify it in the same way as a square-bracket array. I guess the creators of the patch system overlooked this or something.
    You also can't modify multiple elements of an array simultaneously, without replacing the entire thing. Probably because the syntax on that would have been kind of tricky, I think.
    Or maybe they just didn't let you do these things because you can do them all individually and it makes the system simpler. I don't know.

    So if you're trying to modify these things, you need multiple entries. There is no way around this at all.
     
  10. JohnColburn

    JohnColburn Space Hobo

    I have found what seems like an incorrect behavior in how patching is implemented. As an example, assume I create the file "MODNAME/objects/apex/apexcurtain/apexcurtain.object.patch" and this is the content:

    Code:
    [
    {"op":"add","path":"/description","value":"foobar"}
    ]
    
    When I start the game from a terminal, I see this error message:

    Code:
    Error: Could not load /objects/apex/apexcurtain/apexcurtain.object asset, using default.
    (AssetException) Could not read variant asset /objects/apex/apexcurtain/apexcurtain.object
    Caused by: (JsonParsingException) Cannot parse json file: /objects/apex/apexcurtain/apexcurtain.object
    Caused by: (VariantPatchException) Could not apply patch to base. Invalid operation: add
    Which seems odd, considering that the patch works just fine if you test it using the patch tester in the tutorial. The patch doesn't work, and the 'apexcurtain' object is undefined in-game.

    So I change the patch content to:

    Code:
    [
    {"op":"replace","path":"/description","value":"foobar"}
    ]
    This time it works as expected. The description of the object is changed.

    So replace works fine, but add is an invalid operation here? A few other miscellaneous tests show that the "add" operation is apparently invalid if the value already exists.

    This is in direct conflict with RFC 6902, which says under the add operation (section 4.1) that "If the target location specifies an object member that does exist, that member's value is replaced.".

    Also: Don't forget that this error ruins the whole object definition. A failed patch (again according to the RFC) should return the original JSON document unchanged, so even if "add" were invalid at this point I should still get the unmodified object in the game. As it stands, the patch fails AND I get perfectly generic items instead.
     
  11. Olxinos

    Olxinos Scruffy Nerf-Herder

    The last behaviour (a failed patch = a failed file parsing) also makes the test operation absolutely useless (whether you add it or not doesn't change much: if something were to fail, the test would fail too and cause the file to be discarded; you may have a better error message but nothing more).
     
  12. Osoreshi

    Osoreshi Scruffy Nerf-Herder

    Your tutorial completely changed my mod development course. Thank you very much good sir.

    Also, in fact, I can think of an use for copy:
    Code:
    [
    { "op" : "copy",
    "from" : "/speciesText/apex/buttonText",
    "path" : "/speciesText/avian/buttonText"
    }
    ]
    UPDATE: Copy command acts like add command, so if there is any previous value in the same path, you will most likely get an unknown error from the game. So code should be something like:
    Code:
    [
    { "op" : "remove", "path" : "/speciesText/avian/buttonText" }, //first erasing any previous value the path may have
    { "op" : "copy",
    "from" : "/speciesText/apex/buttonText", "path" : "/speciesText/avian/buttonText" //then, effectively copying from "apex" to "avian" }
    ]
    Thanks to xxswalitexx for pointing this out. I thought at first the command wasn't implemented.

    This example is from the ..\ai\enableteleporter.aicommand where the same text is written down each time for every race, making an unnecesary bunch of text.
    With this all the values from the apex/buttonText (which are many lines of code) are copied from apex to avian
    Updating or adding values once and reuse them instead of writing them again sounds better.
     
    Last edited: Jan 18, 2015
    The | Suit likes this.
  13. eddiethenewbie

    eddiethenewbie Void-Bound Voyager

    Thanks, this is exactly what I needed. I'm an on-and-off player and modder, and I switched to nightly
    some time ago. Ever since I switched, I haven't really been modding, mostly because I got discouraged when I saw
    that there were no good tutorials on the new patching system. I quit for awhile, and then I came back and found this post.
    Now I can finally get back to modding, thanks to you!
     
    Xordaii likes this.
  14. The | Suit

    The | Suit Agent S. Forum Moderator

    Glad it helped - I will be overhauling the tutorial after new years - to focus much more on path's as that is the hardest part of patching in my opinion.
     
    Xordaii likes this.
  15. apinanaivot

    apinanaivot Cosmic Narwhal

    Why is this not working
    [DOUBLEPOST=1420030746][/DOUBLEPOST]It is for the desert biome
     
  16. Olxinos

    Olxinos Scruffy Nerf-Herder

    You're using the wrong brackets in the wrong places, try that:
    (Edit: if you want to append to an array, you should also use add rather than replace, replace is meant to overwrite something which already exists or fail if it doesn't)
    (Edit2: "tracks" should also be included in the path, then the two new elements should be split in two new operations)
    Code:
    [
        {
            "op":"add",
            "path":"/musicTrack/day/tracks/-",
            "value":"/music/desert-exploration1.ogg"
        },
        {
            "op":"add",
            "path":"/musicTrack/day/tracks/-",
            "value":"/music/desert-exploration2.ogg"
        },
        {
            "op":"add",
            "path":"/musicTrack/night/tracks/-",
            "value":"/music/desert-exploration1.ogg"
        },
        {
            "op":"add",
            "path":"/musicTrack/night/tracks/-",
            "value":"/music/desert-exploration2.ogg"
        }
    ]
    instead of that:
    Code:
    {
        [
            {
                "op":"replace",
                "path":"/musicTrack/day/-",
                "value":{"tracks":"/music/desert-exploration1.ogg", "/music/desert-exploration2.ogg"}
            }
        ],
        [
            {
                "op":"replace",
                "path":"/musicTrack/night/-",
                "value":{"tracks":"/music/desert-exploration1.ogg", "/music/desert-exploration2.ogg"}
            }
        ]
    }
     
    Last edited: Dec 31, 2014
  17. apinanaivot

    apinanaivot Cosmic Narwhal

    It did not work[DOUBLEPOST=1420036760][/DOUBLEPOST]
    :facepalm: my mod was missing modinfo file...
    Does not still work though
     
    Last edited: Dec 31, 2014
  18. AstralGhost

    AstralGhost Pangalactic Porcupine

    Check error log.
     
  19. apinanaivot

    apinanaivot Cosmic Narwhal

    [DOUBLEPOST=1420040154][/DOUBLEPOST]I guess that means that it does not know what desert is...
    Maybe they have changed the name of the desert biome and i still have the old desert files in unpacked assets
    no... it is still in the new assets as well
     
    Last edited: Dec 31, 2014
    AstralGhost likes this.
  20. Osoreshi

    Osoreshi Scruffy Nerf-Herder

    day and night tracks values are arrays, arrays are written with []

    Keeping replace mode is best since you want NEW tracks to be played only, and not the game's tracks
    Code:
    [
            {
                "op":"replace",
                "path":"/musicTrack/day/tracks",
                "value":["/music/desert-exploration1.ogg", "/music/desert-exploration2.ogg"]
            },
            {
                "op":"replace",
                "path":"/musicTrack/night/tracks",
                "value":["/music/desert-exploration1.ogg", "/music/desert-exploration2.ogg"]
            }
    ]
    You dont need "/-" in the path, since you are completely removing old values and adding your own values, so you are working on root path.
     

Share This Page