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

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

  1. Shadow Wolf TJC

    Shadow Wolf TJC Spaceman Spiff

    I noticed that the syntax was right as well, so the 1st thing that I thought was maybe the directory didn't exist. After a quick check, I realized that, indeed, the directory was wrong.

    Anyways, good luck on your future modding endeavors.
     
  2. Alec Valentine

    Alec Valentine Big Damn Hero

    Already managed to find what the problem was, and as The Suit said, it doesn't work on already existing characters.

    Tried to add the commented reset button, but it doesn't show in the GUI, luckily I can fix that by using commands in-game.
    Code:
    {"op" : "add",
    "path":"/btnResetTools",
    "value":{
           "type" : "button",
          "base" : "/interface/scripted/mmupgrade/resetbutton.png",
          "pressedOffset" : [0, -1],
           "position" : [10, 22],
          "callback" : "resetTools"
        }
    
    }
     
  3. bk3k

    bk3k Oxygen Tank

    You should add into your tutorial how to properly use patch batches paired with test conditions. They're VERY useful, and don't add a lot of complexity.



    So compare this
    Code:
    [
      {
        "op" : "copy",
        "from" : "/speciesText/apex/buttonText",
        "path" : "/speciesText/avian/buttonText"
      }
    ]
    to this
    Code:
    [
      [
        {
          "op" : "copy",
          "from" : "/speciesText/apex/buttonText",
          "path" : "/speciesText/avian/buttonText"
        }
      ]
    ]
    All I did is encapsulate the patch within brackets. That's obviously simple enough, but why bother?

    Well look at the post I quoted. It was pointed out that the "copy" operation would error out if there was already something at the destination. So removing the destination first was advised. But is that really good enough? If you tried to remove something that isn't there, I believe you'd also get an error(unless I'm mistaken). So suppose you don't know in advance what is there? You can view vanilla assets but you don't know what other mods are doing that may load ahead of you, do you?

    And here's where I do this.
    Code:
    [
      [
        {
          "op" : "test",
          "path" : "/speciesText/avian/buttonText",
          "inverse" : false
        },
        {
          "op": "remove",
          "path": "/speciesText/avian/buttonText"
        }
      ],
      [
        {
          "op" : "copy",
          "from" : "/speciesText/apex/buttonText",
          "path" : "/speciesText/avian/buttonText"
        }
      ]
    ]
    I tested for the presence of the path. If the condition fails, all subsequent operations in the current batch will abort(without error). However... the next batch will still execute. And with the first batch, we can be assured that the destination for the "copy" operation doesn't exist.

    I commonly use this for "add" or "replace" operations. I want to be sure the destination exists first. One could test for each level of the path and create if necessary. For example
    Code:
    [
      [
        {
          "op" : "test",
          "path" : "/ability",
          "inverse" : true
        },
        {
          "op" : "add",
          "path" : "/ability",
          "value" : {}
        }
      ],
      [
        {
          "op" : "test",
          "path" : "/ability/scripts",
          "inverse" : true
        },
        {
          "op" : "add",
          "path" : "/ability/scripts",
          "value" : []
        }
      ],
      [
        {
          "op" : "add",
          "path" : "/ability/scripts/-",
          "value" : "/scripts/bk3k/meleeThrust.lua"
        }
      ]
    ]
    I never ended up using this patch on anything except for playing around, but this is a good reference.

    Now where that REALLY comes in handy is making your mod optionally compatible with other specific mods. View their mods and observe a unique change. Then test for that change, or lack thereof. You can have a batch that covers the normal state of things absent their mod, and another that covers the scenario of their mod being present.

    In extreme cases, you could run multiple test conditions within the same batch, although I don't know any cases where that's been necessary. But you COULD if you needed to.
     
    Last edited: Nov 23, 2016
  4. amirmiked12

    amirmiked12 Spaceman Spiff

    i have lots of item how to add them in player.config.patch faster ..u know writing lots of item????
     
  5. sayter

    sayter The Waste of Time

    Yea. Do it how everyone else does it: Copy/paste, edit. Copy/paste, edit. Copy/paste, edit. Welcome to modding.
     
    lazarus78 likes this.
  6. Nemasys

    Nemasys Cosmic Narwhal

    I find this site extremely convenient for making patch files. I use is all the time. The only downside is that, like most JSON sites, it doesn't like comment lines. You'll need to remove any before it will work.
     
  7. bk3k

    bk3k Oxygen Tank

    Indeed. And sometimes that will give you sub-optimal patches for what you're doing. They'll still work though.
     
  8. lazarus78

    lazarus78 The Waste of Time

    Function over form, personally. At least I know it will work. If it doesn't, it is likely my error, not the patch.
     
  9. apinanaivot

    apinanaivot Cosmic Narwhal

    Sorry to bother again, but I still don't understand pathing, I am trying to add this:

    Code:
      {
        "op": "add",
        "path": "/eyeChestTreasure/1/-",
        "value": {
          "weight": 1,
          "pool": "WMPeyeWeapon"
        }
      },
    To this:
    Code:
      "eyeChestTreasure" : [
        [1, {
          "fill" : [
            {"pool" : "eyeTreasure"}
          ],
          "pool" : [
            {"weight" : 0.7, "pool" : "basicTreasure"},
            {"weight" : 0.3, "pool" : "eyeTreasure"}
          ],
          "poolRounds" : [
            [0.40, 2],
            [0.40, 3],
            [0.20, 4]
          ],
          "allowDuplication" : false
        }]
      ],
    Basically I want to add WMPeyeWeapon to the "pool" where basicTreasure and eyeTreasure are.

    EDIT:

    I also tried this and it didn't work:
    Code:
    [
      {
        "op": "replace",
        "path": "/eyeChestTreasure/0/1/pool/0/weight",
        "value": 0.6
      },
      {
        "op": "add",
        "path": "/eyeChestTreasure/0/1/pool/1",
        "value": {
          "weight": 0.1,
          "pool": "WMPeyeWeapon"
        }
      }
    ]
     
    Last edited: Mar 17, 2017
  10. xaliber

    xaliber Scruffy Nerf-Herder

    @apinanaivot
    I think you're missing the square brackets and using incorrect path. It should be:
    Code:
    [
        {
        "op": "add",
        "path": "/eyeChestTreasure/0/1/pool/-",
        "value": {
          "weight": 1,
          "pool": "WMPeyeWeapon"
        }
      }
    ]
    /eyeChestTreasure/0/1/pool/-
    means you're adding to the eyeChestTreasure parameter, in the 0th array, in 1st array, in pool parameter.

    If you encounter the {} brackets, that means it uses a parameter, e.g. eyeChestTreasure. If you encounter the []brackets, that means it uses array. Array starts from 0, hence to select the the first array you don't use 1 but 0.
     
  11. apinanaivot

    apinanaivot Cosmic Narwhal

    I tried your fix, it didn't work. If you want to try for yourself, you can download my mod here: http://community.playstarbound.com/resources/weapon-megapack.4217/
    The file is located at "mods/Weapon Megapack/treasure/biome.treasurepools.patch.BROKEN". You have to remove the .BROKEN from the file extension for the file to work.

    You can then test if it works in-game by typing /spawntreasure eyeChestTreasure, if it does work Eye axes should spawn when you type the command.

    Until I get this fixed half of the weapons in my mod will be unavailable without commands.
     
  12. xaliber

    xaliber Scruffy Nerf-Herder

    For some very curios reason your /oceanFloorChestTreasure/0/1/pool/- is causing problem (it cannot detect the path). Because it's causing problem, everything else in the biome.treasurepool.patch won't be read.

    But it should be fixed now. As in, it's correct according to the JSON patcher. Haven't tested it in game.

    Attached is the file. Just change the file name without the .txt, Starbound forums won't upload .patch file.
     

    Attached Files:

    apinanaivot likes this.
  13. apinanaivot

    apinanaivot Cosmic Narwhal

    Thank you very much!
     
  14. bk3k

    bk3k Oxygen Tank

    I know you already have your answer, but I still think this can help you in the future.

    The readability standards of the treasurepools are lacking and makes manually patching harder for most. I think combining brackets on the same line hurts more than anything. Here's what it SHOULD look like IMO.
    Code:
      "eyeChestTreasure" : [
        [
          1,
          {
            "fill" : [
              {
                "pool" : "eyeTreasure"
              }
            ],
            "pool" : [
              {
                "weight" : 0.7,
                "pool" : "basicTreasure"
              },
              {
                "weight" : 0.3,
                "pool" : "eyeTreasure"
              }
            ],
            "poolRounds" : [
              [
                0.40,
                2
              ],
              [
                0.40,
                3
              ],
              [
                0.20,
                4
              ]
            ],
            "allowDuplication" : false
          }
        ]
      ],
    
    Reading that instead, can you see where your mistake happened? I made the scope as easy to follow as possible. I myself probably would use

    Code:
              [  0.20,  4  ]
    rather than
    Code:
              [
                0.20,
                4
              ]
    per my example, but doing the first way makes the path much clearer when people may need to patch specific parts (at the expense of looking just a little more funky).
     
    apinanaivot and xaliber like this.
  15. Zancuno

    Zancuno Existential Complex

    I'm having a bit of trouble patching in something. To make the Lucario Race feel like it's a part of the game, I am trying to implement dialog of what the Lucario Race would say to every in game race and what every in game race would say to a Lucario. Although I encountered a problem patching the dialog into the converse.config. After messing with the code for a while I finally got an answer from the log that is telling me what is wrong.

    Lucario is not an index.

    So I dug deeper into the code and saw something that has put the entire project to a dead stop.

    The patch in the player.config.patch file
    Code:
    { "op" : "add", "path" : "/species", "value" : [ "lucario" ] }
    
    Is not activating, removing that ability for the game to recognize it as an index...

    Is this feature locked out?

    (It is not allowing a patch, obvious in notepad++ by the line of code staying black instead of turning green (green indicating it can work))

    Do I have to replace "value" with something else, or is there no way of patching?
     
  16. lazarus78

    lazarus78 The Waste of Time

    Your patch is incorrect.

    Code:
    [
      {
        "op": "add",
        "path": "/species/-",
        "value": "MySpecies"
      }
    ]
    
    Useful site for making patches.
    http://chbrown.github.io/rfc6902/
     
  17. Zancuno

    Zancuno Existential Complex

    That didn't work either :/

    Also the second line of the patch
    Code:
    { "op" : "add", "path" : "/defaultCodexes/lucario", "value" : [ "lucariodirective", "lucarioprologue", "lucarioorigins", "protectorate1", "protectorate2" ] }
    
    does work

    so it's not the path

    maybe it has something to do with my saves carrying old data.... I'm going to delete them (my progress!! T~T) and see what it does... it might not be implementing the new code..

    Edit: You..... seriously have to be kidding me.... just because there was a space... moving it away from the left side it didn't work.... you have to be messing with my mind.... Starbound is this picky now? A hit of the space bar rendered it not usable?...
    I'll click Best Answer on your post now :/
     
    Last edited: Apr 18, 2017
    Sakura Aurora Lunaris likes this.
  18. bk3k

    bk3k Oxygen Tank

    Negative!

    Believe it or not, there can be more than one wrong thing. You MUST understand JSON itself first and foremost. http://www.json.org/

    In JSON terms, "species" from /player.config is an array, not an object. Objects have values that are referenced with string names, arrays do not. Arrays only have values that are addressed in numeric order(essentially just a list). Therefore you CANNOT patch it in the way you are attempting. What lazarus78 said is correct. You want to add your species to the end of the array, so

    Code:
    [
      {
        "op": "add",
        "path": "/species/-",
        "value": "lucario"
      }
    ]
    
    But that only takes care of one thing, not others.

    Yes, because "defaultCodexes" is an object. That patch would not work to add to an array.

    Now to your next point of confusion.
    Unless I misunderstand what you wrote, you are under the impression that your problem patching /dialog/converse.config has anything to do with /player.config - It doesn't. Patching doesn't work that way.

    So let me make you a patch that would work. Although I'll just copy the Apex version, and leave the actual text swapping to you.
    Code:
    [
      {
        "op": "add",
        "path": "/greeting/lucario",
        "value": {
          "default" : [
            "Hello.",
            "How are you?",
            "How are you doing?",
            "Nice to meet you.",
            "I hope you are well, my friend.",
            "Big Ape is watching.",
            "I hope you have a pleasant day.",
            "It is good to see you.",
            "Can I help you?",
            "Good day, my friend.",
            "Hello, stranger.",
            "Welcome.",
            "Welcome, my friend.",
            "It is nice to meet you.",
            "Please, stay a while.",
            "How do you do, my friend?",
            "Greetings, stranger, and welcome.",
            "Hello, friend.",
            "How is it going?",
            "Have a good day.",
            "Can I offer you anything, my friend?",
            "Pleased to meet you, friend.",
            "Have a good day.",
            "Make yourself at home.",
            "Hi there.",
            "Hi.",
            "Ok, nice to meet you.",
            "Alright, my friend?",
            "Hey there, strange person.",
            "Hello to you."
          ]
        }
      }
    ]
     
    lazarus78 likes this.
  19. Zancuno

    Zancuno Existential Complex

    Thanks to what was previously said, my problem was resolved. Once the patch file was fixed to make sure the lucario was added to the player.config species list, all of my other patches started working and my project was able to continue. The reason why I was having trouble was because that one line of code in the patch file wasn't working, it wasn't recognizing lucario as an index being a race. As of such, using lucario in the converse files was giving me constant "Could not apply patch, "lucario" is not an index in "/greeting/lucario/" in the log. Once that line of code was fixed, it started working. Thanks for the advice though, although the way you worded it..... it felt like a punch in the gut....
     
  20. bk3k

    bk3k Oxygen Tank

    No harm meant. Maybe I came across harshly. Glad you got it going now.
     

Share This Page