Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Help!
#1

Limiting Binary Addition & Subtraction?

Archive: 6 posts


I want to use my 17bit system to produce a health system, but how do I limit adding/subtracting past certain values?

Say I want max health to be 10110 (22), how can I stop an addition from going beyond 10110?

The whole system is instantaneous, so I can't just disable addition when that threshold is met, since the addition would have gone past the threshold and then frozen (so 11111 could be reached and then addition would be prevented).

Also, same idea for subtraction. Say I want to limit damage to that of within one health of a unit, possible?
2011-03-03 08:44:00

Author:
SSTAGG1
Posts: 1136


Binary comparators are pretty easy to write: So just do your addition, test to see if the value exceeded that threshold, and if it did, replace the sum with the threshold value.

For 17 bit values, that does wind up being a lot of logic: feeding two 17-bit values into a comparator, getting a comparison result out... and then using the comparison result to select one of two 17 values - it's a lot of wiring... so that part of it isn't going to be a lot of fun...
2011-03-03 09:43:00

Author:
tetsujin
Posts: 187


When its over disable the addition and change the value to max. It should work but it flashes quickly to value over the max and if its subtracted same time it will jump to the max.

Or you could subtract with value over max by subtracting max amount from current health and subtracting that from current health.
2011-03-03 09:50:00

Author:
waD_Delma
Posts: 282


Problem with that is that when I want to 'heal' the player, each subtraction would result in a final overflow value, which activates the unit's death. It got very annoying separating modifications into add/sub, especially when I had multiple changes occurring within a short timespan. Too many tags, and the modification I made to accept subtractions without causing death creates a slight delay, which could result in actual damage being treated as healing......bah!

I think hardwiring an override to set value as X when >X is the best option, since I want damage to decrease bit value, and healing to increase (due to issue with final overflow causing death if otherwise).

This is going to get annoying really quickly.
2011-03-03 16:43:00

Author:
SSTAGG1
Posts: 1136


Thinking outside the box for a moment: Take 0 to be maximum health and you die at > x. Damage is positive input, heal is negative input.

You can use the sign bit to determine whether the change in magnitude is positive or negative. You can also do the same with the result. If your overall change for this frame is negative, and the result is negative, then set all values to 0. So that's a single NAND gate to do the checks and 17 AND gates to reset everything to 0. That's a neat, instant max limit on your health.

For min health limiting, then you just need a comparator. You won't need to select the max or min value to route to the answer as you are dead. The true/false response from the comparator is enough to tell you that. The only caveat is that you use signed math, which you should be doing anyway to handle addition and subtraction.


I'd still stick with timers though
2011-03-03 17:02:00

Author:
rtm223
Posts: 6497


Hmm, perhaps. I like the flexibility of the bits for different values. I suppose I could just go back to using my impact + tag strength system. It worked, and was fairly flexible. Thanks for the help anyway.2011-03-04 02:35:00

Author:
SSTAGG1
Posts: 1136


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.