• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to Add Fractions of Gold?

Status
Not open for further replies.
Level 4
Joined
Mar 20, 2014
Messages
67
So here's my GUI -
  • Gold Income
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in GoldMines and do (Actions)
        • Loop - Actions
          • Set Gold = ((Real((Custom value of (Picked unit)))) / 60.00)
          • Player - Set (Owner of (Picked unit)) Current gold to (((Owner of (Picked unit)) Current gold) + ((Custom value of (Picked unit)) / 60))
          • Floating Text - Create floating text that reads (String(Gold)) above (Picked unit) with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
          • Floating Text - Change the lifespan of (Last created floating text) to 1.10 seconds
      • Unit Group - Pick every unit in LumberMills and do (Actions)
        • Loop - Actions
          • Set Lumber = ((Real((Custom value of (Picked unit)))) / 60.00)
          • Player - Set (Owner of (Picked unit)) Current lumber to (((Owner of (Picked unit)) Current gold) + ((Custom value of (Picked unit)) / 60))
          • Floating Text - Create floating text that reads (String(Lumber)) above (Picked unit) with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
          • Floating Text - Change the lifespan of (Last created floating text) to 1.10 seconds
It adds the correct amount of gold, but I'd like it to be actually adding gold. Three * .33333 does in fact equal one (well .9999999999 for you smartalecs) but it doesn't add one, so what would be the next best way without getting rid of the system?
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
actually .999999 is not considered 1 and when the game converts real number (number with decimal point) into integer (number without decimal point), it gets rid of everything behind the decimal point - it doesn't round up or down.

So real number 0.99999 --> gets rid everything behind decimal point --> integer 0

To fix this, you could for example always add 0.99 to your calculated amount, so if it is above .01 or more, it gets rounded up.
 
Level 4
Joined
Mar 20, 2014
Messages
67
But what about a game like Line Tower Wars, they have an income /a second type of income and they add like .006 income per sheep sent. I dont get it.
 
Level 4
Joined
Mar 20, 2014
Messages
67
Well technically speaking it's an income showed in a multiboard but you can tell the income goes up by the amount, I calculated the amount of sheep and it went up a whole number per second after X amount of sheep.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
if it ain't lumber or gold (which are showed in the top bar of UI), then I believe you can just use a real variable and keep track of it that way. Real variable won't delete everything behind decimal point.

Only actual gold and lumber are converted into integers. Custom incomes can be stored in real variable.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Like everyone has been saying, you could keep track of the resource in a real variable and then convert it over to the actual player state resource(s) (i.e. gold or lumber).
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Resources are integers so cannot have a fractional part.

Using triggers you can declare a variable to hold the fractional part for fractional trigger added resources. When this fractional variable overflows you take the whole units and add them to the player's resources.

There are two ways to to store fractional parts.
Easy: Use a real variable. This automatically contains both whole number and fractional components so the fractional part can be added directly to the variable. The problem is that real type in WC3 uses 32 bit floats so there is a finite precision. Especially when mixing small fractions and large fractions there may be a loss of the small fractions.
Hard: Use an integer to represent a fixed point number. Chain many together to define an absolute precision. Fixed point is what real life electronic financial interactions use. The problem is you will need complicated functions to manipulate and process the fixed point number which may not be worth the effort. It will also be much slower than using a real due to the multiple jass function calls needed.
 
Status
Not open for further replies.
Top