Trying to set a json object in a property

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Trying to set a json object in a property

Post by mfrizzell »

I have a property called Weapons that has json objects for each weapon stored. I need to pull out one Weapon(object) and set it as a property in the property EquipedWeapon. I'm have a bit of trouble with the latter. I want each set object to overwrite the previous object but not only am I not getting that it seems that I'm not able to set the object with the correct fields. Here is what I have.

Code: Select all

[h: WeaponList = listSort(json.fields(Weapons),"A+")]

<!-- Present an input to select a Weapon to edit, or to 
add a new Weapon -->
[h:status=input(
"whichWeapon|"+WeaponList+"|Choose a Weapon to Equip|LIST|SELECT=0 VALUE=STRING"
)]
[h:abort(status)]

[h:selectedWeapon = json.get(Weapons, whichWeapon)]

[h:EquipedWeapon=json.set("{}",EquipedWeapon, selectedWeapon)]
Any help would be most welcome.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Trying to set a json object in a property

Post by CoveredInFish »

Isnt it just this?

Code: Select all

[h: WeaponList = listSort(json.fields(Weapons),"A+")]
[h:abort(input(
"whichWeapon|"+WeaponList+"|Choose a Weapon to Equip|LIST|SELECT=0 VALUE=STRING"
))]

[h:EquipedWeapon = json.get(Weapons, whichWeapon)]
It really depends on how you structured your data. If you want EquipedWeapon to hold a single object keyed to weapon name then do it like this...

Code: Select all

[h: WeaponList = listSort(json.fields(Weapons),"A+")]
[h:abort(input(
"whichWeapon|"+WeaponList+"|Choose a Weapon to Equip|LIST|SELECT=0 VALUE=STRING"
))]

[h:EquipedWeapon = json.set("", listGet(WeaponList, whichWeapon), json.get(Weapons, whichWeapon))]

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Trying to set a json object in a property

Post by mfrizzell »

Thanks for the response but I get this error on both pieces of code.

Code: Select all

Argument number 2 to function "listGet()" must be type "BigDecimal", but was passed "BattleAxe" of type "String".
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Trying to set a json object in a property

Post by mfrizzell »

I managed to get it to work by changing the last line. Here is the new code.

Code: Select all

[h: WeaponList = listSort(json.fields(Weapons),"A+")]

<!-- Present an input to select a Weapon to edit, or to 
add a new Weapon -->
[h:status=input(
"whichWeapon|"+WeaponList+"|Choose a Weapon to Equip|LIST|SELECT=0 VALUE=STRING"
)]
[h:abort(status)]

[h:selectedWeapon = json.get(Weapons, whichWeapon)]
[h:EquipedWeapon=selectedWeapon]
Thanks for your help
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Trying to set a json object in a property

Post by CoveredInFish »

Ah ... stupid me, didnt noticed the input() returned the string, I expected index number. Glad you got it working.

Post Reply

Return to “Macros”