Hallo i wondering how can i convert JSON file into structure like this one.. (based on lists)::pika:
var/list/Dialogue = list(
"MrSatan" = list(
"INTRO_1" = list(// shown dialogue option always
"Options" = list(list("Nothing" = "End"), // shown dialogue option always
list("Over Level" = 9000, "I'm Over 9000 Lv" = "STRONGER_THAN_ME"),// shown dialogue option when player is over 9000 lv
list("Under Level" = 9000, "Teach me how to fight" = "NEW_STUDENT")// shown dialogue option when player is under 9000 lv
),
"Body" = list("Hi i'm the strongest man in the world!","What are you looking for?")// dialogue body
),
"STRONGER_THAN_ME" = list(
"Options" = list(list("Let's begin!" = "End")),
"Body" = list("Are you redy?")
),
"NEW_STUDENT" = list(
"Options" = list(list("Sure" = "End"), list("No way!" = "End")),
"Body" = list("Bring me 5 flowers..")
),
)
)
//JSON
[
{
"MrSatan": {
"INTRO_1":
{
"Options" : {"Let's begin!" : "End"},
"Body" : ["Are you redy from JSON"]
}
}
}
]
This is how i've made it with datum. It's work fine. Its much easier for me:(
card
parent_type = /obj
var/list/someVar
New(list/data)
name = data["name"]
icon = 'Cards.dmi'
icon_state=data["icon_state"]
someVar = data["someVar"]
var/list/global_cards
proc/LoadCards(fname)
var/i
var/card/C
global_cards = json_decode(file2text(fname))
for(i in 1 to global_cards.len)
C = new/card(global_cards[i])
global_cards[i] = C.name
global_cards[C.name] = C
mob/verb/OnInit()
set category="json";
world << "starting json load";
LoadCards("Code/data.json")
proc/GetCard(cname)
var/card/c = global_cards[cname]
return c
//JSON
[
{
"name": "As",
"icon_state": "as",
"someVar": ["some1", "some2"]
},
{
"name": "Król",
"icon_state": "k",
"someVar": ["some1", ["some2_1+","some2_2"]]
},
{
"name": "10",
"icon_state": "10",
"someVar": "Dyszka"
},
{
"name": "9",
"icon_state": "10",
"someVar": "Dziewięć"
}
]