View Full Version : Multiple/Divide Ability
mr_h
July 17th, 2006, 03:24
I've seen in a couple of other posts that it is possible to take a variable and multiple it/divide it to get your final result. However, being the code moron that I am, I can't figure out how to do this :(
Can someone assist me here? This is what I'm doing.
1) I'm allowing the players to enter their Strength score.
<stringcontrol name="strength_full">
<bounds rect="298,51,31,16" />
</stringcontrol>
2) There will be two more variables: strength_half and strength_quarter.
These should be self calculating (IE, players shouldn't have to enter anything) and of course, they set themselves to half and quarter of the strength score, respectivly.
Now, I know that the functions are either * or /, but the codes I've seen in alternative character sheets confuses me (Source names? op +? erf.
I know it sounds like I'm asking someone else to do the work, but this one has stumped me for two days, so I'm forced to beg for help :D
Any help would be appreciated, thanks!
H
Azrael Nightstar
July 22nd, 2006, 01:04
Well, I know how to do this so I'll finally ANSWER a question instead of just posting them constantly, but someone else might know a simpler/better way.
To accomplish this I use a "dummy value", basically a number control that exists only to be a factor in other controls. It should look like this:
<numbercontrol name="dummy">
<invisible />
</numbercontrol>
Then your half-strength control would look like this:
<numbercontrol name="strength_half">
<bounds rect="[wherever you want it]" />
<source name="strength_full" op="+" />
<source name="dummy" op="/" valuemap="0:2" />
<value type="readonly" />
</numbercontrol>
The quarter would be the same, but valuemap="0:2" would have a 4 rather than a 2.
You will also need to change the strength_full from a stringcontrol to a numbercontrol. Stringcontrols allow non-integer values (integer being positive or negative whole numbers and 0) but cannot be added/subtracted/multiplied/divided.
This is how these work:
<numbercontrol name="strength_half"> opens the control, you know how that works. As I said numbercontrols only work with integers.
<bounds rect="[wherever you want it]" /> locates the field on the page, again you know how this works.
<source name="strength_full" op="+" /> This tells the control to take the value that's in "strength_full" and do something with it. op="+" tells the program what that something is, which is add it.
<source name="dummy" op="/" valuemap="0:2" /> This again tells the control to take the value from "dummy". op="/" tells it to divide by that value.
valuemap="0:2" tells it that if the value is 0, it should be changed to 2. This keeps you from having to make a different dummy control for each number you want to multiply or divide by. So you can use "dummy" again with your quarter strength figure, and valuemap 0 to 4 instead, since you're dividing by 4.
<value type="readonly" /> keeps the value from being changed. This prevents something happening like a player using the mouse roller to roll the value up accidently, and ensures the control gets ALL its information from the sources you've told it to.
</numbercontrol> ends the control
Edit: Almost forgot, it's worth noting that when you divide numbers and get a non-integer value (a decimal), fantasy grounds rounds the value down to the nearest integer (2.7 becomes 2). At the moment, there is no way to get FG to round differently (like to the nearest whole, so that 2.7 would become 3).
mr_h
July 22nd, 2006, 03:26
Azrael, you are a god amongst posters. It works perfectly now. I had edited my code to something close, but not exact, and I never changed strength_full to numbercontrol. Makes a huge difference.
I appreciate the help :D
/bookmarks the page to let others know if they ever ask.
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.