Log in

View Full Version : Two xml/script math issue - need help



nezzir
April 29th, 2007, 15:37
I have two issues I'm having trouble figuring out. If anyone can help, I'd appreciate it greatly.

Multiplying a number:
I need to link to a stat and multiply it by 2, etc. It's a movement chart. I can link the stat ok, but I can't figure out how to multiply the number I've linked to by 2 (or more).


Issue 2, a little more complicated:
I'd like to create a line with:
A linked number, 3 state circles, and a total line.

Starting with the linked number, if no state circles are checked the total is 1/2 the linked (round up).
If one state circle is checked, the total is the linked.
If 2 are checked, the total is the linked +10
If all three are checked, the total is the linked +20

Example:

25 o o o 13
25 x o o 25
25 x x o 35
25 x x x 45


If anyone can push me in the right direction on these, I'd appreciate it.

Goblin-King
April 30th, 2007, 10:15
Multiplying a number:
I need to link to a stat and multiply it by 2, etc. It's a movement chart. I can link the stat ok, but I can't figure out how to multiply the number I've linked to by 2 (or more).
I assume you are using the <linkednumber> template defined in the d20 ruleset.

Your best method would be to override either the onSourceUpdate function of your control, to perform the entire calculation in a custom script, or the onSourceValue function to override the calculation for the single field you need multiplied.

For an example, look at the AC calculations in charsheet_combat.xml or just do a search with the function names in the ruleset.


Issue 2, a little more complicated:
I'd like to create a line with:
A linked number, 3 state circles, and a total line.

Starting with the linked number, if no state circles are checked the total is 1/2 the linked (round up).
If one state circle is checked, the total is the linked.
If 2 are checked, the total is the linked +10
If all three are checked, the total is the linked +20

Example:

25 o o o 13
25 x o o 25
25 x x o 35
25 x x x 45


If anyone can push me in the right direction on these, I'd appreciate it.
This is indeed a bit more involved. One way to do this would be to define a custom control for the row of checks, that would display the check boxes and store the number of ticked boxes in a field in the database. You can see an example of this e.g. in the character sheet weapon entry ammo counter (scripts/charsheet_ammocounter.lua). This could make a nice generic template as well...

After you have the number of checked boxes in the database field, use it as a source for the resulting field, and do the calculations using the methods in the answer to your first question.

Another solution that might be a bit easier but involves more fields would use the <checkbox> template to define the three boxes, then using the value fields (which are numbers of 0 or 1) as sources to the final calculation. You would be able to tick any boxes in this case though an not just the 0-3 leftmost ones.

nezzir
April 30th, 2007, 12:03
You would be able to tick any boxes in this case though an not just the 0-3 leftmost ones.

Thank you very much. That gives me a push in the right direction. I think the bubbles are a better solution in this case because the advances have to be taken in order. If I modify the ammo script (which I've done once already for a wound tracker), then you could simply hover over it and mouse up to check the dots.

Thanks again.

FryCook
April 30th, 2007, 20:41
hey nezzir,

sounds like you are working though a WFRP2 skill list. i've been wrestling with this as well, but the d20 charsheet_skill is a bear.

nezzir
May 1st, 2007, 12:55
hey nezzir,

sounds like you are working though a WFRP2 skill list. i've been wrestling with this as well, but the d20 charsheet_skill is a bear.

Warhammer... Um... I have no knowledge of a Warhammer ruleset, nor would I be at liberty to say if I were aware of said ruleset. This message will self destruct in 10 seconds.

I solved the problem, for now, by hard coding the entries. The stat numbers are brought over automatically, but the check boxes are just for tracking and have no effect on the totals box. The totals box is simply updated manually.

I plan to go back and revisit this once the ruleset is complete and tested.

My ruleset, we'll call it ...Whammy... is close to being complete. I have a pretty good team helping me key in data, I'm porting the screen information over from my previous ...Whammy... ruleset, and I have a guy that promised to help me with some spiffy new graphics. If you'd like to help us, send me a private message and I'll set you up with the links.

Here's a screenie of the ...Whammy's... front page:
https://mywebpages.comcast.net/nezzir/files/fg2-charsheet.jpg

I'm nearly done with the character sheet and getting ready to move on to the GM and Player assist screens while the rest of the team are keying in spells and new careers.

nezzir
May 1st, 2007, 13:08
Is it possible to link objects from the modules on the character sheets? I'd love to be able to "drag" frequently used spells entries to the spell sheet...

Goblin-King
May 2nd, 2007, 12:12
Is it possible to link objects from the modules on the character sheets? I'd love to be able to "drag" frequently used spells entries to the spell sheet...

Yes, the d20 character sheet's spells page uses this functionality.

There are several methods available depending on the exact functionality you wish to get and what you need to perform as a result of the linking. The d20 spell sheet copies relevant details from the spells module to the character sheet, and maintains a shortcut to the spell description contained in the actual module.

nezzir
May 2nd, 2007, 17:22
Yes, the d20 character sheet's spells page uses this functionality.

There are several methods available depending on the exact functionality you wish to get and what you need to perform as a result of the linking. The d20 spell sheet copies relevant details from the spells module to the character sheet, and maintains a shortcut to the spell description contained in the actual module.

I know you're busy, but if you get a second I may need some help on this one... (or anyone if they can help)

I don't need any of those bells and whistles on the sheet. I just need to drag and drop my spells into a persistent list.

As it stands, that xml/lua combo is a monster! It refers to the class and level of the PC, track preparation mode, tons of things. Brilliant scripting really, but so dense I'm having trouble stripping it down.

All I need is to drag a spell from my list (that functions just like the d20 list) to the spell sheet and have it list name, description, and one other field (plus a link).


Edit: This seems to me like a fundamental function. I've thought of a half dozen uses for it already. If we could get a code snippet that would perform this function, I think a lot of people could use it.

nezzir
May 2nd, 2007, 22:07
To give back a little, here is my simple math multiplication script based on the code in "Charactersheets_Templates.xml". It is used to multiply base movement by two.


Effect:
Creates a small number field that links to another field and multiplies the result by 2.


<sheetnumber name="cscharge" source="csmove">
<!-- *This is the name of the field and the name of the soucefield -->
<anchored>
<to>combatmoveframe</to>
<position>insidetopleft</position>
<offset>69,20</offset>
<size>
<width>34</width>
</size>
</anchored>
<modifier>-1</modifier>
<font>sheetnumbersmall</font>
<frame>
<name>modifier</name>
<offset>2,2,2,2</offset>
</frame>
<scorefield>mc</scorefield>
<!-- *This references the original move score -->
<script>
function onSourceUpdate()
setValue(math.floor(sources[scorefield[1]].getValue() * 2));
<!-- *This is the meat of it. It gets the value of the "mc" variable and multiplies it by 2 -->
end

function onInit()
addSource(scorefield[1]);

super.onInit();
end
</script>
<font>sheetnumbersmall</font>
</sheetnumber>



I didn't really know what I was doing, so there may be some code in there that's not needed, or there may be a better way to do it, but this works.

Hope someone finds it useful.

Now if I could just puzzle out the way to check the state of a checkbox and perform an if/then on it, I'd have the answer to the second part of my question. I'll start working on that next.