[Concept Help] Calling jsons within jsons + frames

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
Xaelvaen
Dragon
Posts: 498
Joined: Wed Aug 31, 2011 9:49 pm
Location: Somewhere between Heaven and Hell

[Concept Help] Calling jsons within jsons + frames

Post by Xaelvaen »

I'm working on a project for my Shadowrun Anarchy campaign framwork to help build Shadow Amps. Each such Shadow Amp is stored as a json, and then all the Amps are stored within a single property json. To build the Amp, and then store it in the json, isn't too hard. My real problem is, how do I get a frame to create only as many tables as necessary to show the number of amps an individual has, and how do I get it to organize them by level?

You could relate this to a spellcaster having spells, and you want to arrange them from highest level to lowest to display on a frame. I'm absolutely clueless as to what sort of html / code to build in order to make a variable number of tables with the data appear. In truth, I'm not sure how to even tell the code to get the information for the exact number of shadow amps inside the core json.

I assume I'd need some sort of way to count the number of jsons within the json and then use a foreach to get the properties?

Code: Select all

[h: shadowAmpList=getProperty("Amps")]
[h, foreach(Amp,shadowAmpList,""), CODE:{

[h: ampName=json.get(Amp,"Name")]
[h: ampLevel=json.get(Amp,"Level")]
}]
I honestly don't even know if the code above would work to get the information.

The next step, which I'm clueless about, is how to make it take that information, and create a frame that -only- has a table for each of the appearing Amps, no more, no less.

Any help (even just pointing at the right part of the wiki) is greatly appreciated.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy

User avatar
jackolas
Cave Troll
Posts: 28
Joined: Tue Apr 16, 2013 8:19 am
Location: Netherlands
Contact:

Re: [Concept Help] Calling jsons within jsons + frames

Post by jackolas »

think this should work:

Code: Select all

<!-- Amp window -->
[H: RNA_RowColor =  "DBD9C0"]

[H: shadowAmpList=getProperty("Amps")]

[R, frame("Amp Window", "width=350; height=500; temporary=1;"):{
<!-- Show Data -->
<table border="1" cellpadding="1" bgcolor="white" width="100%"><tr>
	<table border="0" cellpadding="0" width="100%">
		<tr bgcolor="black">
			<th width="4"></th>
			<th style="padding-top:4; padding-bottom:4; color:white" valign="middle" align="left">Amp Name</th>
			<th width="4"></th>
			<th style="padding-top:4; padding-bottom:4; color:white" valign="middle" align="center">Level</th>
			<th width="4"></th>
		</tr>
		[R, foreach(Amp, shadowAmpList, ""),CODE:{
			<tr bgcolor="[R: RNA_RowColor]">
				<td width="4"></td>
				<td align="left">[R: json.get(Amp,"Name")]</td>
				<td width="4"></td>
				<td Align="center">[R: json.get(Amp,"Level")]</td>
				<td width="4">[H: RNA_RowColor =  if(RNA_RowColor == "DBD9C0", "B3AF94", "DBD9C0")]</td>
			</tr>
		}]
	</table></tr>
</table>
}]
just copied this out of my D&D 5th spell database and adjusted to your variables. so should work

User avatar
Xaelvaen
Dragon
Posts: 498
Joined: Wed Aug 31, 2011 9:49 pm
Location: Somewhere between Heaven and Hell

Re: [Concept Help] Calling jsons within jsons + frames

Post by Xaelvaen »

Oh that's perfect - how would I sort that list so that the highest level spells appear at the top of the table, and lowest at the bottom? Would sorting the json high to low before the foreach work?
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy

User avatar
jackolas
Cave Troll
Posts: 28
Joined: Tue Apr 16, 2013 8:19 am
Location: Netherlands
Contact:

Re: [Concept Help] Calling jsons within jsons + frames

Post by jackolas »

if your shadowAmpList is an json ARRAY with contains Json OBJECTS you could use json.sort to sort the array on level before drawing the frame.

help for more info about sort: http://www.lmwcs.com/rptools/wiki/json.sort

User avatar
Xaelvaen
Dragon
Posts: 498
Joined: Wed Aug 31, 2011 9:49 pm
Location: Somewhere between Heaven and Hell

Re: [Concept Help] Calling jsons within jsons + frames

Post by Xaelvaen »

That's what I expected - didn't know if the foreach would keep the order. Works perfect mate, thanks =)
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy

Post Reply

Return to “Macros”