Integers and Floats with decimals

Discussion in 'RPG Maker VX Ace' started by InspiredByBitcoin, Jul 19, 2016.

  1. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Greetings RPG Maker community,

    I apologies if I have missed something or put this in the wrong section. I've been a long time observer of these forums over the last few years and it has helped me to a great extent, But the time has come to come here myself and request your help personally.

    Thanks to Tsukihime for helping me over Facebook.

    Boring Intro

    Anyway, I've been producing a Bitcoin inspired RPG game which is a hybrid Roleplaying-Simulation(Idle/Upgrade)-Strategy(Time managed), Production has been on-going for 7 months almost, Most of which has been fixing scripts to make them compatible with others and what-not.
    Usually every time I come to a halt due to bugs I can't comprehend myself, I find an answer pretty simply either on this forum or another.


    Anyway I've started dealing with mathematics in scripts within common events and I've came across an issue, I'm trying to make a variable hold a decimal value such as 0.0000001 by using:
     

    $game_variables[1] = 10.0.to_f
    $game_variables[2] = $game_variables[1] * $game_variables[3]
    Control Variables: [0001:pAYOUT] /= 1000000
    $game_variables[4] += $game_variables
    [1]


    Problem: When I do this the fourth variable ($game_variables[4]) holds the value of "1.0e-07", where it has moved only one decimal place, Then uses the number after: 'e-##' to display the number of decimals I'm supposed to have.

    It is really frustrating because I have had this working once before and when I tried to add one more decimal it's been errors in Game_Interpreter line 1411 (which I fixed) or other unprecedented bugs, like the one I'm experiencing.

    I'm sure I'm simply overlooking something and I would appreciate any person that can help me with forcing my fourth variable to have a value such as 0.00000001  >  100.99999999.

    Screenshots can be supplied if necessary.

    Thank you for taking the time to read this or reply.
    IBB
     
    Last edited by a moderator: Jul 19, 2016
    #1
  2. Rinobi

    Rinobi Veteran Veteran

    Messages:
    563
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMVXA
    I'm gonna be honest here. I'm not 'entirely' sure what the problem is, so forgive me if my interpretation of this question is off the mark.


    It seems like you want to bypass scientific notation and just have Ruby print out the decimal places? If so, try:

    Code:
    $game_variables[1] = 10.00
    $game_variables[2] = $game_variables[1] * $game_variables[3]
    $game_variables[1] /= 1000000.00
    $game_variables[4] += $game_variables[1]
    $game_variables[4] = "%f" % $game_variables[4]
     
    #2
  3. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Thanks for taking the time to read my help request. 

    The feature of my game utilizes these variables by displaying them on-screen in a custom HUD which is updated each in-game hour, upon setting the switches on as displayed in this gif.

    [​IMG]


    To show amount of satoshi/bitcoin the player has earnt. My formula for displaying a variable seems to work up until a point, Then it throws out random fractions instead of what I want.

    I can display and store 0.00001 in a game_variable by floating one of the other variables, the smallest amount of Satoshi in real life situations is 0.00000001 so it would be ideal if I could use 8 decimal places after "0.", As I mentioned I'm having a bit of luck doing this with only 5 decimal points after "0." (for example 0.00034).
    But at 6am the value of that variables becomes a random fraction with many more decimals than I need.

    [​IMG]



    I'm certain this is possible somehow, But I'm no proficient programmer. Hopefully this helps you understand my issue and what I want to achieve.

    Thanks
    IBB
     
    Last edited by a moderator: Jul 21, 2016
    #3
  4. Rinobi

    Rinobi Veteran Veteran

    Messages:
    563
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMVXA
    Then it's as I thought. The solution I provided should override scientific notation. Look closely:

    SyFy_Override_00.PNG


    SyFy_Override_01.PNG





     




     








    It's the same value, printed out as plain decimals in attempt two. I couldn't replicate your example exactly because I did not know the value of global variable #3, this should work regardless.


    Alternatively...

    SyFy_Override_02.PNG SyFy_Override_03.PNG


    SyFy_Override_04.PNG


    SyFy_Override_01.PNG





     
     
    Last edited by a moderator: Jul 21, 2016
    #4
    InspiredByBitcoin likes this.
  5. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Woah!! 

    Thanks for the response, Taking the time to test out a solution and share it with me.

    Global Variable[3] is player controlled with value of 0(nothing invested) and up. That variable controls Hash/s printed out on-screen.

    So when the player buys a hash with "120/G" Hash/s increase by 1, The player can buy as many hashes as they want.

    [​IMG]


    I pre-defined game_variable[1] separate to the rest of the 'multiplication script' which runs hourly in a common event.

    [​IMG]
    $game_variable[1] refers in my game to [9]. I just decided to use 1-4 to simplify. No problem for me to change.
    [​IMG]
    This is how the common event looks, with different [#numbers] albeit simple to copy and paste new code.



    I'm going to try your solution now.

    Once again, Thanks for the detailed answer.

    I'll let you know if it works on my end (Using the 8 decimal points (0.00000001 - 100.00000000))

    IBB
     
    Last edited by a moderator: Jul 21, 2016
    #5
  6. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Okay, upon extensive testing, I've concluded: 

    Your solution to work well so far, except for one thing. It works perfectly for a division of 1000000.00, but not for a division only x100 more ($Var / 100000000.00).

    For example:
     

    [​IMG]


    This provides this result, in-game:
    (also showing the control of a multiplication variable we've previously discussed control by the player on a PC, and now how and why I split the script we've been discussing into three parts. long events, looping long common events and an automatic event at the start of the game which pre-defines variables.) 
     

    [​IMG]


    It's worth noting once again, It works flawlessly with a lower division, hence not providing another long anomation.

    Thanks 
    IBB
     
    #6
  7. Zeriab

    Zeriab Huggins! Veteran

    Messages:
    1,196
    Likes Received:
    1,237
    First Language:
    English
    Primarily Uses:
    RMXP
    The bitcoin amount behaves pretty much like an integer that just happens to have the decimal point moved 8 positions.


    I recommend you have one variable containing the total amount of bitcoins counted in satoshi the player has. That is an integer value.


    Whenever you need to display it you can extract the two parts using the / and % operators.


    satoshi = amount % 10**8
    bitcoins = amount / 10**8




    *hugs*


     - Zeriab
     
    Last edited by a moderator: Jul 21, 2016
    #7
  8. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Hi Zeraib,

    Thanks and hugs for dropping in,
    I currently have bitcoin and satoshi separated since the only way i could get it working at the start was by using whole numbers, Rinobi has given me the code change I needed to work within the limits VXa has, I guess anyway, So that way I can display Bitcoin as 1 variable in-game, anything higher than '0.99999999' could be called a full BTC, on the same line. 

    Slightly confused with your code, mainly why use division and pct's.
    I've also never seen double '*' only double dots for arrays and using rand(#..#).

    I have to apologize for my lack of understanding  ;_;
    It's weird how it doesn't work by adding an extra couple of 0's to the division scriptlet.

    Is there a way to show me how it works? i've got to duplicate the working code and adapt it over several events too :'( 

    Thanks
    IBB
     
    Last edited by a moderator: Jul 21, 2016
    #8
  9. Rinobi

    Rinobi Veteran Veteran

    Messages:
    563
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMVXA
    Alright. Ruby doesn't want to actually show us more than 6 decimals or so before switching to scientific notation. This is usually more convenient to read (assuming you know how), but under these circumstances, we actually want to print out 8 decimal places since the lowest possible value (satoshi?) for bitcoin is 0.00000001. That's my train of thought, here's my solution:

    SyFy_Override_05.PNG


    SyFy_Override_06.PNG


    SyFy_Override_07.PNG SyFy_Override_08.PNG SyFy_Override_09.PNG SyFy_Override_10.PNG





     




     








    The page switches back and forth between adding 1 satoshi, and adding 1 bitcoin.
    With a value of 0, the display would read: 0.00000000


    Adding 100 satoshis, the display would read: 0.00000100


    Adding 250 bitcoin, the display would read: 250.00000100


    I believe that accounts for the entire spectrum of possible bitcoin values.


    Basically... use "%0.08f" instead of "%f" to force the 8 decimal places.

    View attachment 43409
     
    Last edited by a moderator: Jul 22, 2016
    #9
    InspiredByBitcoin likes this.
  10. InspiredByBitcoin

    InspiredByBitcoin Villager Member

    Messages:
    18
    Likes Received:
    2
    Location:
    England
    First Language:
    English
    Works perfectly Rinobi,

    Thank you very much.
    IBB
     
    #10

Share This Page