#(Zeelia) Add a key & value to a data script container

33 messages · Page 1 of 1 (latest)

abstract mantle
#

Hi! I have created a data script container which contains static data for a custom quest system.
This data script is saved inside a player flag to keep track of which quests the player has accepted.
Now, I want to add a dynamic key and value to the data script before adding it to the player flag.
However, when I try to add the dynamic data, I can't use the data script anymore, I can't get any values from it.
Is there a way to add a dynamic value, or are data script containers static, or am I doing it wrong?

quest_test:
    type: data

    name: Test Quest 1
    description: hello
    steps_list:
        1: Talk to the NPC
        2: Bla bla
        3: Bla bla bla
    rewards:
        apple: 4

quest_save:
    type: world
    events:
        on player kills entity:
            - define questWithStep <script[quest_test]>.currentstep:1
            - flag player quests:->:questWithStep
simple craneBOT
#

(Zeelia) Add a key & value to a data script container

#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

frosty thistle
#
    events:
        on player kills entity:
            - define questWithStep <script[quest_test]>.currentstep:1
            - flag player quests:->:questWithStep

there are many things wrong here

#

i'd say you fix these first

#

regarding dynamic values, they are static, but they do not parse tags within them

#

so you can have tags in there, and use the tags

#

!t parsed_key

round thornBOT
frosty thistle
#

!t scripttag.parsed_key

round thornBOT
# frosty thistle !t scripttag.parsed_key

Returns the value from a data key on the script as an ElementTag, ListTag, or MapTag.
Will automatically parse any tags contained within the value of the key, preserving key data structure
(meaning, a tag that returns a ListTag, inside a data list, will insert a ListTag inside the returned ListTag, as you would expect).

Returns

ObjectTag

frosty thistle
#

!t elementtag.parsed

round thornBOT
frosty thistle
#

to parse them at runtime

abstract mantle
#

Thank you!! I'll take a look at it!

austere burrow
# round thorn

Keep in mind that this tag shouldn't be used, if the element that's getting parsed relies on user input.

abstract mantle
#

Thank you Icecapade, there's no user input involved!

#

Can you give me a few more pointers, I don't quite understand what I need to do.
I started with getting the parsed version of my data script, as it would allow me to dynamically add a key and value to the data script, if I understand correctly?
And then I tried to add my key and value by parsing it into the parsed data script, but it doesn't work. I know I've definitely misunderstood 😂

- define questWithStep <script[quest_test].parsed>
- define questWithStep questWithStep.parsed_key[mynewkey]:1

Just to clarify, my goal is to take a copy of the data script, save it inside a list inside a player flag, and then add an additional key and value which wasn't in the original data script.
I basically want to save all the quest data scripts inside a list called player.flag[quests]
And I want to add a new key and value to each data script inside of that player flag list, so I can keep track of which step of the quest the player is at.

#

Also tried doing something like this:

- define questWithStep <script[quest_test]>.parsed.mynewkey:1

And using ElementTag.parsed_key when trying to read the "mynewkey", but that just gives me the error Tag <[questWithStep].parsed_key[mynewkey]> is invalid!

chilly locust
#

If there are tags you should consider parsed_key otherwise you should be using data_key to pull information, you can also use submapping to pull keys.

Ex: <script[my_script].data_key[rewards.apple]> will return 4 as that is the value you've submitted for apple

chilly locust
abstract mantle
#

Thank you!
I am able to pull information from the data script, but only if it is already there in the beginning.
How do I go about adding new data to it?

If I do this:
- flag player quests:<script[quest_test]>
I can successfully pull any information from the data script.

But if I try to add a new key and value to the data script, I can no longer pull any data:
- flag player quests:<script[quest_test]>.parsed_key[currentstep]:1

So I think I'm not adding the new data correctly.

austere burrow
#

Did you read the guide yet? It explains how tags work.

#

!guide

round thornBOT
abstract mantle
#

Sorry Icecapade! I had read the guide, but I got confused how tags work. I'm used that in other programming languages everything is calculated, whereas in Denizen everything seems to be regarded as text unless inside tags.

I couldn't figure out how to save new data inside the data script, so I simply resolved to using a flag with the data I needed to save. Thanks!