Guide:MEB/Chapter1

From Starbounder - Starbound Wiki
Jump to: navigation, search

Chapter 1 - Understanding JSON:

Understanding the format of JSON is extremely easy to pick up. But before you do there are a few important things to keep in mind. So before we jump straight into the coding of Starbound. We are going to look at JSON syntax - common mistakes - and how to check them before we move on. This section is because this is the area where many early starters make the most mistakes.

Though if you know what Array, List, Map is, it would make things easier. There is a much easier lay mans approach we can take. Don't worry we will follow it up with examples and a test.

  1. Comma's are used to separate pieces of data.
  2. The last piece of data in a bracket does not require a comma
  3. Only the last bracket in a sequential bracket closure requires a comma if and only if there is a piece of data after the sequential bracket closure.
  4. Numbers are not enclosed in quotes
  5. True and False statements are not enclosed in quotes.
  6. All strings (text) are enclosed in quotes
  7. All brackets should be closed in proper order.


Now lets take a look at a simple recipe for bow

{
  "input" : [
    { "item" : "fullwood1", "count" : 10 },
    { "item" : "plantfibre", "count" : 1 }
  ],
  "output" : {
    "item" : "bow",
    "count" : 1
  },
  "groups" : [ "plain", "all", "tools" ]
}


Now you have a basic idea of what it looks like.

{
  "kind" : "burnedmessage",
  "definition" : { //Kind and definition are both in the first quote
    "type" : "text", //Type size text are within the definition bracket.
    "size" : 0.85,
    "text" : "^shadow;Burned" // Text is the last line in the 
    definition bracket hence doesn't require a comma
	} // The comma is not required here as no more data follows it. 
}


Using the rules listed above. Correct the following code snippet. This code snippet is completely made up and set simply for testing your understanding.

{
    "mode": floor,
    "priority": 1
    "variants": "1"
    "distribution": "/biomes/distributions.config:undergroundChests"
    "type": "object"
    "objectSets": [
        {
            "pool": [
                [
                    1,
                    statuspod,
                ]
            ],
            "parameters": {
                "understood": true
            }
        },
    }
]


Now to see if you are right or not. We will check the code using an JSON interpreter.
JSON Lint will check to see how valid your code is. So once it shows you are right. The problem is just because JSON lint shows the code is "valid" does not always mean its right. It just means it right based on JSON standards, which slightly differe from that of starbound. For example JSON lint has no problems with Numbers being in quotes, or true and false statements, but starbound does. Hence you will have to manually check your code for that.
Once you have double checked the code follows all the rules as listed above and it passes JSON lint. You can confirm the answer here

Now lets move on to the next step