Lone Wolf Development Forums EABA Powers (Scripting question)
 Register FAQ Members List Search Today's Posts Mark Forums Read

 Notices Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528. If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com. - The Lone Wolf Development Team

Senior Member

Join Date: May 2013
Posts: 1,458

April 9th, 2019, 07:33 PM
I've started yet another project that I'm not sure if I'll make it through, but for now, I'm wondering if I could get some scripting help.

If I'm reading the rules correctly, each power costs 1 point to add to the character. After that, every point spent raises the power level by 2. So in the portal, I set the incrementer to have an interval of 2, and that's working fine. But I'm having trouble calculating the point cost.

The script I'm using is below, and this is what's happening.
I add a power. Now I'm left with 9 power points. (This is correct so far.)
Now I increment the power level. It goes from 1 to 3. (This is also correct.)
The problem is, I still have 9 power points. Going from 1 to 3 doesn't subtract a point from my resources.
After that, it works fine. Going from 3 to 5 subtracts 1 point, then 5 to 7 and so on.

I've tried different ways of coding the script, but I can't get it to work how I want.

And yes, I sometimes miss obvious things.

Code:
```    <!-- Each power that is added by the user costs 1 point
Each point spent after that buys 2 points.
-->
<eval index="1" phase="Setup" priority="5000"><![CDATA[
~we must ignore bootstrapped abilities from races and abilities added via advances
if (isuser + origin.ishero >= 2) then
var uval as number
var cost as number
uval = field[trtUser].value

cost = (uval - 1) / 2
if (cost < 1) then
cost = 1
endif

hero.child[resPP].field[resSpent].value += cost
endif
]]></eval>```
#1
Senior Member

Join Date: Mar 2013
Location: Greater London, UK
Posts: 2,483

April 9th, 2019, 11:34 PM
So "(uval -1) / 2"

Does that give the correct subtraction, or should it be "(uval + 1) / 2"?

Farling

Author of the Realm Works Import tool, Realm Works Output tool and Realm Works to Foundry module

Donations gratefully received via Patreon, Ko-Fi or Paypal
#2
Senior Member
Lone Wolf Staff

Join Date: May 2005
Posts: 12,949

April 10th, 2019, 07:30 AM
I would not trust an interval to protect what you're trying to do. Users can still edit the number and type in whatever they want. Instead, I would add a second field that is the power level, and is calculated at 2x field[trtUser].value. Then, you're having the user control the number of points they spent, and displaying the final power level separately. (Or adjust the finalize script on trtUser to display the power level, but that might look odd if the user edits it when it says 4, because they'd see a 2).

I'd read up on the Savage Worlds Wiki - they do a similar thing where the user needs to control dice sizes, and they also need to only show even numbers to the user, but still have a single click change the die size from d4 to d6.
#3
Senior Member
Lone Wolf Staff

Join Date: May 2005
Posts: 12,949

April 10th, 2019, 07:35 AM

cost = (uval - 1) / 2

So, at a uval of 0, the cost = -1/2 (but then you apply a minimum)
At a uval of 2, the cost = 1/2 (and the minimum applies)
at 4, the cost = 3/2
At 6, the cost = 5/2

That doesn't match the costs you were describing.
#4
EightBitz
Senior Member

Join Date: May 2013
Posts: 1,458

April 10th, 2019, 11:31 AM
Quote:
 Originally Posted by Farling So "(uval -1) / 2" Does that give the correct subtraction, or should it be "(uval + 1) / 2"?
It gives the correct subtraction for the division by 2, but not, I now realize, for the final calculation. Your reply gave me this idea:

Code:
```         cost = (uval - 1) / 2
cost = round(cost,0,1) + 1```
And that works.
#5

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Lone Wolf Development Web Site Announcements Realm Works Forums     Realm Works Discussion         Realm Works in Action         Realm Works Feature Requests     Realm Works in Action     Realm Works Feature Requests Hero Lab Online Forums     Hero Lab Online Discussion     HLO - Pathfinder 1st Edition     HLO - Pathfinder 2nd Edition     HLO - Starfinder     HLO - Shadowrun Hero Lab Forums     HL - Pathfinder Roleplaying Game     HL - D&D 5th Edition SRD     HL - Shadowrun     HL - Mutants & Masterminds     HL - d20 System     HL - World of Darkness     HL - Call of Cthulhu     HL - 4th Edition     HL - Savage Worlds     HL - Cortex System     HL - Authoring Kit     HL - User Projects     HL - Alternity (user-created)     Hero Lab Discussion Army Builder Forums     Army Builder Army Builder Data Files     Babylon 5: A Call to Arms     Battlefleet Gothic     Blood Bowl     Black Powder, Bolt Action, Hail Caesar, Judge Dredd, and Pike & Shotte     Confrontation - English     Kings of War (2nd Edition)     Lord of the Rings (Tabletop)     Mordheim     Necromunda     Starship Troopers     Star Wars: X-Wing and Armada Miniatures Game     The 9th Age     Warhammer Ancient Battles     Warhammer 40,000     Warhammer Fantasy 8th Ed.     Warhammer Historical: The Great War     Warhammer Fantasy 3rd Ed.     Warlord     Warmachine & Hordes     Warmaster Card Vault Forums     Card Vault Card Vault Data Files     MLB Showdown     Lord of the Rings CCG     .hack//ENEMY     Vs. System     Yu-Gi-Oh!     D&D Miniatures

All times are GMT -8. The time now is 12:57 AM.

 -- Default Style -- Majestic Contact Us - Lone Wolf Development Forums - Archive - Top