Passing property name through Macro() and nested jsons

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
Oriet
Cave Troll
Posts: 30
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Passing property name through Macro() and nested jsons

Post by Oriet »

Being that I can't seem to stay with simple macros, and not wanting to have several macros for some weapons, I decided to try making a complex attack macro. I know the theory of what I want to do, but I can't seem to get it executed. I've been able to get several steps done, but there are two bits I can't seem to get functioning no matter how much I bash at my keyboard. I apologise for this being long, but it's proving quite tricky for me.


Issue #1: Passing a variable holding a property name through Macro() for later use:
With this I'm needing to hold the name of a property, to both gather information from and update with new values throughout the entire macro-chain. The reason I'm going this route is so that I can have token properties with weapon variables for what the characters have equipped, with a macro able to call on each weapon property but utilise the same attack macro-chain on a library token.

I'm obviously doing something wrong as the property name and values don't seem to get properly passed or accessed. I've tried having the property name in quotes as the value of the property, and I've tried passing only part of the property name to add to the other part of the property name to call on it, and neither have worked. I have been able to assign the property values and pass those along, but that leaves me without having the property name to call for updating the property's values.


Issue #2: Accessing nested json objects:
Normally I try to avoid nesting json objects or string property lists (including with each other), but it seems to be the only way to get what I'm wanting. As a quick run down, I'm wanting a list of variables holding weapon information (name, size of clip, rounds remaining, etc). One of these variables should then hold a list of firing mode/option variables, each of which holds further variables specific to that option (damage amount, damage type, rounds expended, etc). This is so that I can have variable power levels, rate of fire settings, kill/stun settings, and other such, but only display info relevant to each weapon.


Here are the properties and macros I've come closest to getting success with.
[spoiler=Used Campaign Properties]

Code: Select all

attrib.brawn (Br):3
attrib
.finesse (Fi):3
attrib
.size:0
equip
.weapon.two
skill
.Ranged_Combat:type=broad; attrib=Fi; value=0; trained=0
skill
.Rayguns:type=tech; broad.skill=skill.Ranged_Combat; value=0; trained=0
[/spoiler]

[spoiler=Weapon Property]

Code: Select all

{"name":"blaster pistol", "tech":"rayguns", "modes":{"kill":{"damage":"9", "type":"energy", "expends":"1", "range":"200"}, "stun":{"damage":"9", "type":"fatigue", "expends":"1", "range":"20"}}, "clip.current":"50", "clip.max":"50", "reload":"2"} 
[/spoiler]

[spoiler=Weapon Macro]

Code: Select all

[h,macro("[email protected]:combat"): "equip.weapon.two"] 
[/spoiler]

[spoiler=Attack Macro: attack.macro.2 on Lib:combat][/spoiler]


I'm pretty lost on all of this and so welcome all help in getting this working. I'm also willing to take a different approach if needed, so long as the outcome arrives at what I'm needing. I will also state now that I am thinking of changing to Dialog() instead of Input(), to avoid potential property resets in case something happens while it's up and so that characters can check again which target in the list they want (for when they run up against multiple similar opponents, like a squad of stormtroopers or hive gangers). I don't think that will change either of these options, but I suppose it's something to keep in mind should snippets of code be offered.
Kill them all, and let the Game Master grant the exp!

ImageImage

User avatar
Oriet
Cave Troll
Posts: 30
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Passing property name through Macro() and nested jsons

Post by Oriet »

Complaint: Tendinitis makes it hard to make macros, or do much on a computer in general, especially when untreated for a couple weeks.

Realisation: It would seem that using [wiki]varsFromStrProp()[/wiki] with [wiki]json.toStrProp()[/wiki] affects json objects nested in the json object they are applied to. It would seem this is what was causing the problem I was having with nested json objects. This unfortunately requires more code to assign the needed variables, but shouldn't be an issue as long as the number of contained variables is not über long.
Kill them all, and let the Game Master grant the exp!

ImageImage

User avatar
wolph42
Deity
Posts: 9852
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Passing property name through Macro() and nested jsons

Post by wolph42 »

issue 1:

don't use "" that way you're passing that string as a value instead of the value of the variable. However moreover I would strongly advise you to use user defined functions. Dig the wiki thourgh to see how they work, but they are
1. a lot easier to work with
2. faster

2. neste json objects aren't *that* hard, however your structure isn't very usefull its better to use the weapon name as key so:

Code: Select all


WEAPONS 
= {blaster pistol: {"name":"", "tech":"rayguns", "modes":{"kill":{"damage":"9", "type":"energy", "expends":"1", "range":"200"}, "stun":{"damage":"9", "type":"fatigue", "expends":"1", "range":"20"}}, "clip.current":"50", "clip.max":"50", "reload":"2"} , "another pistol":{...}}
 

This way you can store a property either on the token or on a lib:token 'Weapons' and retrieve lets say the 'blaster pistol\modes\kill\range' as follows:

Code: Select all

wpnLib = getLibProperty("Weapons", "lib:Token")
wpn = json.get(wpnLib, "blaster pistol")
mode = json.get(wpn, "modes")
kill = json.get(mode, "kill")
range = json.get(kill, "range") 

you can embed all these into one line
or
you get IRC lindsays toolbox which contains json.pget and json.pset in whic case this becomes:

Code: Select all

range = json.pget(wpnLib, "blaster pistol/modes/kill/range") 

Post Reply

Return to “Macros”