Instructions on how to halve your life points with the click of a button without having to first divide them by 2

If you have a suggestion for the site, create a topic here and telll us about it
Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Instructions on how to halve your life points with the click of a button without having to first divide them by 2

Post #1 by Christen57 » Sun Mar 13, 2022 10:38 pm

A user requested a button to automatically halve life points without having to first manually calculate your current life points divided by 2. https://forum.duelingbook.com/viewtopic.php?f=13&t=20620

There's an easy way to do this using javascript.

Create a new javascript bookmark, name it whatever you want (i'll be naming mine "halve life points"), and in the URL/Address box, copy and paste this code.

Code: Select all

javascript:Send({"action":"Duel", "play":"Life points", "amount":-Math.floor(player1.lifepoints/2)})


Save your bookmark, go duel or into solo mode, and click the bookmark to automatically halve your life points.

Here's a video of all the steps on how to do this. I'm using Vivaldi for this so the steps may be slightly different for you depending on what browser you're using. https://gfycat.com/recentlittleghostshrimp

Those of you who are interested/curious, here's a brief summary of how this code works.

javascript:Send({"action":"Duel", "play":"Life points", "amount":
This is the part of the code that basically sends a request to duelingbook asking it to modify the player's life points. This code is always executed by default each time any player types an integer into the life point box and hits Enter on their keyboard to submit that integer.

-Math.floor(player1.lifepoints/2)})
This is the part of the code that basically tells duelingbook whether we want to increase our life points or decrease them, and by how much. In this case, I have it set up so that it takes the lifepoints of player1 (who is always by default going to be you the player), divides it by 2, and submits the result to duelingbook so duelingbook can lower your life points by that end result.

You may have noticed that I included "Math.floor" in my code. This is because, in yugioh, whenever you're supposed to halve your life points for whatever reason, like if you're trying to activate Solemn Judgment, but you have an odd number of life points instead of an even number, you're supposed to halve your life points but round it up. https://yugioh.fandom.com/wiki/Forum:25_Life_Points_divided_by_2?
https://www.reddit.com/r/Yugioh101/comments/fg8qqm/lp_halving/

You are, however, still considered to have paid "half your life points" for these effects.

Even if you have only 1 life point left, the ruling is that you can still activate things like Solemn Judgment — you'll just be paying 0.5 life points so you have 0.5 life points, which will immediately be rounded back up to 1 life point, essentially allowing you to use Solemn Judgment "for free" in that situation.

When we run this code to calculate half our life points, if we have, for example, 5 life points, it would normally return 2.5, but since duelingbook can't accept 2.5 as a valid number to subtract from our life points (since it only accepts integers), Math.floor will round this number down to 2, a number that duelingbook will accept, and the reason we're trying to round this down to 2 instead of up to 3 is because we're not actually requesting duelingbook to leave us with 3 life points. We're requesting duelingbook to subtract our life points by 2 which will leave us with 3 life points — the correct amount of life points we should be left with in this scenario — since half of 5 is 2.5, and 2.5 rounded up is 3.

It's easy to divide simple numbers like 8000 (our starting life points) by 2 in our heads, so, for the most part we might not need this code or a calculator, but when it comes to more complicated numbers like 1234, 625, 5300, 1900, 777, and 350, suddenly we end up needing a calculator, which slows down the duel as we're now taking up extra duel time for no reason just to calculate half of a number rounded up (something that other simulators like EDOpro automatically do for you).

Return to “Suggestions”

Who is online

Users browsing this forum: No registered users and 162 guests