Help with macro: list only keys, and json.set erroring

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
2tail
Kobold
Posts: 2
Joined: Tue May 10, 2016 7:57 am

Help with macro: list only keys, and json.set erroring

Post by 2tail »

Two parts:
1) I have a json object (middle part) that I want to only list the keys for in a list you can be seen below.
2) the last line, the json.set line, is erroring out.

Code: Select all

[h: status=input("z|"+json.toList(TType)+"|What Base Skill is it from:|LIST|SELECT=1 VALUE=STRING")]
[h:abort(status)]

[h:status = input(
    "Index|"+json.toStrProp(getProperty(z))+"|What Sub-skills exist right now:|LIST|SELECT=1 VALUE=STRING",
	"Name|Stuff|What What Sub-skill you want to add:",
	"Value|value|What What rank will you have:")]
    [h:abort(status)]

[h: z=json.set(z, Name, Value)]

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Help with macro: list only keys, and json.set erroring

Post by aliasmask »

z is not a json but a string selected from a list as it was converted from the array TType. Lets assume that string represents the name of a token type variable which contains a json object. You would need to use PROPS and not list to represent those values. It still doesn't make z a json.object since you didn't assign it that value. You need to separate your variables "gets" out of the input and assign them to a variable. For example:

Code: Select all

[H: skillListProps = json.toList(TType)]
[h: abort(input(strformat("propName|%{skillListProps}|What Base Skill is it from:|LIST|SELECT=1 VALUE=STRING")))]

[H: object = getProperty(propName)]
[H: strProp = json.toStrProp(object)]
[h: abort(input(
   strformat("Index|%{strProp}|What Sub-skills exist right now:|PROPS"),
   "Name|Stuff|What What Sub-skill you want to add:",
   "Value|value|What What rank will you have:"
))]

[H: object = json.fromStrProp(Index)]
[H: object = json.set(object,Name,Value)]
Of course, I'm only basing this on your existing code and the variable types may not be this way. This code could use some error checking as well.

Post Reply

Return to “Requests for HELLLLP!”