I'm surprised with the result of this use of json.get:
[h: json1 = json.set("","shield",4,"sword",2,"bastard sword",1)]
[h: json1 = replace(json1,"bastard ","")]
[r: json.get(json1,"sword")]
The result is:
[2,1]
A json object can have 2 elements with the same key!?
And if you get the value of this key, you get a json array with all of the values of this key in the json object!!
Anyone knows this use of json.get?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Anyone knows this use of json.get?
Using replace() you have manipulated the JSON as a string - you are "breaking the rules".
The json-functions shouldnt let you assing a key multiple times - it will replace the value instead. But it seems like all values are preserved when you read a json from a string.
The json-functions shouldnt let you assing a key multiple times - it will replace the value instead. But it seems like all values are preserved when you read a json from a string.
Re: Anyone knows this use of json.get?
cool. not sure whether this is ever useful. how did you came accross this?
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: Anyone knows this use of json.get?
It just looks like a failsafe on the hands on the developers of MapTool, so you don't have a crash it returns all values for keys of the string "Sword".
Seems intentional to me, but I'd probably have coded in an error instead.
Seems intentional to me, but I'd probably have coded in an error instead.
Re: Anyone knows this use of json.get?
If I coded it, I'd just return the first value it comes across and delete the other.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Anyone knows this use of json.get?
I notice that ramdomly.
I use json objects to store effects in my framework, something like that:
ACmods: {"armor":4 , "dodge": 1 , "deflection": 2}
When a new effect is aplied to the token, I merge the json objects with a user function to store all bonuses
{"armor":4 , "dodge": 1 , "deflection": 2} + {"deflection" : 1} = {"armor":4 , "dodge": 1 , "deflection": "[2,1]"}
I made this for purposes of stacking or not and to keep stored all bonus for when the effect has finish.
With this "new function" I get a way to do it easily.
I use json objects to store effects in my framework, something like that:
ACmods: {"armor":4 , "dodge": 1 , "deflection": 2}
When a new effect is aplied to the token, I merge the json objects with a user function to store all bonuses
{"armor":4 , "dodge": 1 , "deflection": 2} + {"deflection" : 1} = {"armor":4 , "dodge": 1 , "deflection": "[2,1]"}
I made this for purposes of stacking or not and to keep stored all bonus for when the effect has finish.
With this "new function" I get a way to do it easily.