Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Next
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
Twitch
YouTube
Facebook (EN Publishing)
Facebook (EN World)
Twitter
Instagram
TikTok
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Community
General Tabletop Discussion
*Geek Talk & Media
Need help with a somewhat complex math equation in Java/Acroscript
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="tomBitonti" data-source="post: 6413950" data-attributes="member: 13107"><p>[CODE]</p><p>if(oldStat <= 90) { oldVal = oldStat } </p><p>else if(oldStat > 100) { oldVal = 115 + ((oldStat - 100) * 10) }</p><p>else if(oldStat > 95) { oldVal = 100 + ((oldStat - 95) * 3) } </p><p>else if(oldStat > 90) { oldVal = 90 + ((oldStat - 90) * 2) } </p><p>[/CODE]</p><p></p><p>May I suggest:</p><p></p><p>[Code]</p><p>if (oldStat<0) { oldVal = 0 }</p><p>else if (oldStat > 100) { oldVal = 115 + ((oldStat - 100) * 10) }</p><p>else if (oldStat > 95) { oldVal = 100 + ((oldStat - 95) * 3) }</p><p>else if (oldStat > 90) { oldVal = 100 + ((oldStat - 90) * 2) }</p><p>else { oldVal = 0 + (oldStat - 0) * 1 }</p><p>[/Code]</p><p></p><p>I added in the initial case to force a value which is always zero or higher. (And to create a pre-condition for the remaining tests: The stat is known to be zero or higher for all of those tests.)</p><p></p><p>The case of a stat being at least zero and no greater than ninety was moved to the end. That puts the whole sequence in descending order.</p><p></p><p>The last case was written in the same form as the other case to unify the cases and to show that the per-point cost was one. That makes it easier to add in new branches, or to change the point cost.</p><p></p><p>The form will work, but is somewhat troublesome to use if any update is made: The formulas bake in the point cost for the different ranges.</p><p></p><p>If you don't want to bake in the prior costs, you can use this:</p><p></p><p>[Code]</p><p>if (oldStat<0) {</p><p> oldVal = 0</p><p>} else {</p><p> if (oldStat <= 90) {</p><p> oldVal = oldStat * 1</p><p> } else {</p><p> oldVal = 90 * 1</p><p> if (oldStat <= 95) {</p><p> oldVal = oldVal + (oldStat - 90) * 2</p><p> } else {</p><p> oldVal = oldVal + (95 - 90) * 2</p><p> if (oldStat <= 100) {</p><p> oldVal = oldVal + (oldStat - 95) * 3</p><p> } else {</p><p> oldVal = oldVal + (100 - 95) * 3</p><p> oldVal = oldVal + (oldStat - 100) * 10</p><p> }</p><p> }</p><p> }</p><p>}</p><p>[/Code]</p><p></p><p>And if you are OK to look at the costs as costs cumulative with the prior costs:</p><p></p><p>[Code]</p><p>if (oldStat<0) {</p><p> oldVal = 0</p><p>} else {</p><p> oldVal = oldStat * 1</p><p> if (oldStat > 90) {</p><p> oldVal = oldVal + (oldStat - 90) * 1</p><p> if (oldStat > 95) {</p><p> oldVal = oldVal + (oldStat - 95) * 1</p><p> if (oldStat > 100) {</p><p> oldVal = oldVal + (oldStat - 100) * 7</p><p> }</p><p> }</p><p> }</p><p>}</p><p>[/Code]</p><p></p><p>Notice that the costs add up to 1, 2, 3, and 10, matching the formula initially given.</p><p></p><p>If the language has a "+=" operator, [code]oldVal = oldVal + expr[/code] can be shortened to [code]oldVal += expr[/code].</p><p></p><p>Thx!</p><p></p><p>TomB</p></blockquote><p></p>
[QUOTE="tomBitonti, post: 6413950, member: 13107"] [CODE] if(oldStat <= 90) { oldVal = oldStat } else if(oldStat > 100) { oldVal = 115 + ((oldStat - 100) * 10) } else if(oldStat > 95) { oldVal = 100 + ((oldStat - 95) * 3) } else if(oldStat > 90) { oldVal = 90 + ((oldStat - 90) * 2) } [/CODE] May I suggest: [Code] if (oldStat<0) { oldVal = 0 } else if (oldStat > 100) { oldVal = 115 + ((oldStat - 100) * 10) } else if (oldStat > 95) { oldVal = 100 + ((oldStat - 95) * 3) } else if (oldStat > 90) { oldVal = 100 + ((oldStat - 90) * 2) } else { oldVal = 0 + (oldStat - 0) * 1 } [/Code] I added in the initial case to force a value which is always zero or higher. (And to create a pre-condition for the remaining tests: The stat is known to be zero or higher for all of those tests.) The case of a stat being at least zero and no greater than ninety was moved to the end. That puts the whole sequence in descending order. The last case was written in the same form as the other case to unify the cases and to show that the per-point cost was one. That makes it easier to add in new branches, or to change the point cost. The form will work, but is somewhat troublesome to use if any update is made: The formulas bake in the point cost for the different ranges. If you don't want to bake in the prior costs, you can use this: [Code] if (oldStat<0) { oldVal = 0 } else { if (oldStat <= 90) { oldVal = oldStat * 1 } else { oldVal = 90 * 1 if (oldStat <= 95) { oldVal = oldVal + (oldStat - 90) * 2 } else { oldVal = oldVal + (95 - 90) * 2 if (oldStat <= 100) { oldVal = oldVal + (oldStat - 95) * 3 } else { oldVal = oldVal + (100 - 95) * 3 oldVal = oldVal + (oldStat - 100) * 10 } } } } [/Code] And if you are OK to look at the costs as costs cumulative with the prior costs: [Code] if (oldStat<0) { oldVal = 0 } else { oldVal = oldStat * 1 if (oldStat > 90) { oldVal = oldVal + (oldStat - 90) * 1 if (oldStat > 95) { oldVal = oldVal + (oldStat - 95) * 1 if (oldStat > 100) { oldVal = oldVal + (oldStat - 100) * 7 } } } } [/Code] Notice that the costs add up to 1, 2, 3, and 10, matching the formula initially given. If the language has a "+=" operator, [code]oldVal = oldVal + expr[/code] can be shortened to [code]oldVal += expr[/code]. Thx! TomB [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Geek Talk & Media
Need help with a somewhat complex math equation in Java/Acroscript
Top