Forum rules - please read before posting.

Not subtracting and adding by 0.01 but sometimes by 0.00999999 instead.

Hello everyone,

so I wanted the "bonus-points" for a round to appear and make them count down and add the same time count up on the playerscore. So I created this little setup:

So it starts with checking whether the float "belohnung" (bonus) is already at 0. If not it substracts 0.01 from it and adds 0.01 to the points of the player. Then it waits 0.1 seconds (to make the whole count down thing visible) and check the bonus again. If at 0 it continues and leaves the loop.

The Problem: Everything is fine until you substract a number higher, than 0.09.
So for example, if I substract 0.25 it is fine until 0.20 but as soon as it tries to substract 0.19 it tells me "yeah, the bonus is 0.19 now, but I only added 0.05999999 to the players points". Then it continues and where it should be a bonus of 0.15 it suddenly says "no, the bonus is 0.1499999 now while the player will have 0.09999999 points".

So, is there anything I am doing wrong? Is there any way I could prevent this within the action lists? Otherwise I would have to make a custom script after every step to round these numbers down to two decimal-points, as was suggested in a slightly similar post.

Comments

  • Can you share a screenshot of the Actions with values that cause the issue? I don't follow how subtracting 0.25 from 0.2 is giving you 0.19.

    It sounds like a floating-point error, though. Hard to say exactly where this lies. No casting or anything is involved - AC should be simply adding the two values together.

    First of all, have your initial Variable: Check Action check if you're not Greater Than Zero, not Equal to Zero. That should catch a similar floating point error.

    As for the main issue, you might be able to enforce two decimal points by using a temporary Integer instead. Create a new Integer variable and set up your Actions to do the following:

    • Variable: Set to update the Integer variable with the formula [var:X] * 100 (where X is the ID of the score Float)
    • Variable: Set to increase the Integer variable by e.g. 2 (i.e. 0.02 * 100)
    • Variable: Set to update the Score Float variable with the formula [var:Y] / 100 (where Y is the ID of the temporary Integer)
  • Thank you for looking into my problem. Maybe you missed the first screenshot with the action list... :) Or I got you wrong.
    I created a loop which counts down 0.25 to 0.00 in 0.01 steps. But i think the integer work around should do the trick for me!
  • If anyone encounters the same problem: I solved it by not using "Increase by value" 0.01 or -0.01 but rather using "Formula" and setting for example "[var:1] + 0.01"

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.