Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

As a matter of fact... Not

"JSON is a lightweight data-interchange format."

"JSON is a text format that is completely language independent ."

--from JSON.org

Use "if"?
Unfortunately, no.


Buuuut it's not entirely impossible to make a judgment, for example we can use the following methods:

(The code format provided by itch.... bad)

"Dialog" :{
    "taking_too_long":{
        "if":[
                {
                    "hp_percentage":20,    //health (as a percentage relative to max health)
                    "money":10,
                    //The above are the conditions. Here are just a few examples.
                    //..By the way, comments are actually NOT allowed in JOSN files.
                    //The notes are written here just for ease of understanding.
                    "log":[
                            ["if true! use this"]
                          ]
                },
                {
                    "hp":18,
                    "kills":5,
                    "floor number":5,
                    "floor_type":"um...kitchen?",
                    
                    "need":2,
                    //"need" represents the quantity that needs to be met by the above conditions.
                    //
                    //For example, if "need" is 2, then at least 2 of the above conditions need to be met.
                    //If it is 0, then as long as one of them is met,
                    //If it is -1, then all of them need to be met.
                    
                    "log":[["text text lalala-"]]
                }
        ],
       
        "default":[
                    ["default dealog here"]
                  ]
    }
}

How does it work?

First of all, when the game selects text, try to iterate through all the dictionaries in the array of "if".


Then use the key-value pairs to determine whether the text should be used.
If should, then use the "log" inside it.
If not, then the next dictionary is determined instead.
If none of the conditions in the "if" array are met, use the text "default".


If there is no "if", then just use "default".

(so many if..)


It appears to be quite wonderful, doesn't it? 

The cost is that it will completely destroy the compatibility of the old version of the mod.

However, there are ways to make up for this.
As long as a key-value pair named "version" is added to the ghost's JSON file,
and then the mod creators can choose the appropriate version and fill it in (for example: "version": "2.0"),
the text can be read using the "version" to determine the appropriate method of reading. 

A win-win situation! Yay.


Of course, there are drawbacks as well,(still??)

as implementing all of the above functionalities (reading JSON by version and using "if else") 
may be quite cumbersome...


OR, CMCDEV is long since found a way to do that....?


Anyway.. that's all of it.

Look what I said!

the indentation I worked hard on got messed up like this......