RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Variables hold decimals?

0 Members and 1 Guest are viewing this topic.

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
I have no way of testing this right now otherwise I'd check really fast and wouldn't have to ask.
I was just rolling through the event systems and thought I'd remake my bank event system whenever I get some time, but the thought dawned on me if I would even be able to have a variable hold a number less than 1 and greater than 0, if only for an instant.

Like if I wanted to post a 5% interest on something in the system, I would generally write:

Variable001 == Money
Variable002 == 5
Variable003 == 100
Variable002 /=Variable003      (5/100)
Variable002 += 1                  (1.05)
Variable002 *= Variable001     (1.05*Money)

Does that .05 retain itself for a couple of actions then into 1.05 to do the math correctly? Or does it just round it and Money = Money instead of Money = 1.05*Money?

****
Rep:
Level 83
Well I am pretty sure the standard "Control Variable" feature doesn't work with decimals, but what you could do is use something like this.

Use the "Control Variable" button with the 1st two parts, then using using a call script

Code: [Select]
$game_variables[3] = 100.00
$game_variables[2] /= $game_variables[3]
$game_variables[2] += 1
$game_variables[2] *= $game_variables[1]

As far as I know, that should work, but I don't have VX on this computer so I can't check it. Hope this works

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Oh, very cool. I'll have to check this out later tonight.

**
Rep:
Level 83
Detective Scrotes
Or you could just do
Money *= 105
Money /= 100

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
It's an event system, it's supposed to be pretty easy to set up for newbies. I kind of figured using call scripts would be a little much for an event system, but i'll go with it. It's separated as 100 and 5 because 5 has to be able to be called dynamically in text messages using \v[n]. |n| will equal the interest for your account. It's just less the user has to change when they customize it. Either way, I won't be doing it like 105.

****
Rep:
Level 83
Well I could write up a small script (that would be plug and play) that will allow all variables to hold decimals. Then you could include that in  your event system...though it defeats the purpose of "event system"
Its up to you, grafikal. Would you like me to try that?

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
if the using call scripts like how you said, then i think that should be enough. call scripts are apart of the events lol. it's not hard to explain to someone how to use the call scripts, i mean hell, the way it's set up like that you wouldn't even have to edit anything in that event command anyways, you could change the variable itself from 5 to whatever you want to be the interest. lol, thanks though man

****
Rep:
Level 83
Ok then. Your welcome.
I think I am gonna do that script anyway, because it'll help me out immensely.  :D
See it on the forum....sometime. lol

EDIT:

I looked at it....and I don't think I am gonna do it now. lol. It'd take too much time, and I was hopeing it'd be quick. HAHA....thats what I get
 
« Last Edit: November 13, 2009, 01:52:15 AM by redyugi »

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Using call scripts doesn't work. It won't retain decimals. It rounds to 0 and thus adds 0 gold each time period. :/
I had a system to use decimals that worked, but you could only use preset rates.

****
Rep:
Level 83
It doesn't?? ....let me try it now that I am home.
One question. Did you use "Add money" button and pick the variable? That might be the problem....but like I said, I am gonna try it myself.

EDIT 1:
The Change Money button doesnt work with this. However, the variables are shown right when I call them. (ex. I gave player 500, 5% would be 25. The variable showed 525 {which is right} before and after I added the money. But then I added the money and I checked my money and I only had 1000. Which doesn't add up)
So let me find another way of doing this. Hold on

EDIT 2:
I just realized that you didn't want to give the player money yet. However, when you do, use this
Code: [Select]
$game_party.gain_gold($game_variables[2])
But every thing works right as far as I can see for me. If you still have problems, shoot me your project and I'll see whats wrong. Ok?
« Last Edit: November 14, 2009, 04:53:11 PM by redyugi »

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Ah, very very nice. Check out my Bank System that I updated last night. Here: http://rmrk.net/index.php/topic,31324.0.html That will show you how I had my interest rates going. Download the project at the bottom. I did use the script commands a little bit in there as well. Where I plan to use it is in the Common Event for Interest Rates. I have it set up something like this:

Key: Variable 1 = The timer used for this common event
       Variable 2 = The interest rate, in this example, 5
       Variable 3 = Amount of gold currently in the account
Code: [Select]
Loop:
  >Wait frame(s): 600
  >Variable[0001]:Timer += 1
  >Conditional Branch: If Variable[0001] == 12
    >Call Script:
                  >$game_variables[2] += 100
                  >$game_variables[2] /= 100
                  >$game_variables[3] *= $game_variables[2]
    >Variable[0001]:Timer == 0
Loop Above
  >End
Basically what happened in there was, the interest rate, 5, added 100 to it so it become 105, then divided by 100 so it becomes 1.05. Then the current amount of gold in the account gets multiplied by that. So if you have 1000 gold, your account gold becomes 1050.

At no point does gold get added to the player. It just increases the value of another variable. If I display \v[3] in a text message, it doesn't show that account gold has increased from 1000 to 1050, it just stays at 1000. The only way the player gets money is if they withdraw money from the account, but since the variable doesn't seem to change, it doesn't update so the interest doesn't compound.

P.S. it still doesn't work, so take a look at the project i attached to this post, and let me know what you come up with.
« Last Edit: November 14, 2009, 06:34:13 PM by grafikal »

****
Rep:
Level 83
Well for one, there is a major problem with your Call Script. This
Code: [Select]
$game_variables[2] == $game_variables[4]
Should actually be this.
Code: [Select]
$game_variables[2] = $game_variables[4]
The difference is that what you had is checking if they are equal, and what I just said makes variable 2 equal variable 4.
Now thats the 1st thing I saw. I'll go through and run it again to see if it works. Be back soon.

EDIT:
Well I fixed your demo, and I am uploading it now. I added comments to your common event to show what I changed. It wasn't that bad. Here you go.
« Last Edit: November 14, 2009, 10:30:53 PM by redyugi »

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Ahhh, I seee. I'm just used to seeing the conditional branch with the double equals. lol. I'll download this and check it out real soon. Just have to close some programs and reboot in WindowsOS.

****
Rep:
Level 83
Yea. Its confusing if you don't know alittle bit about programming in general. lol.
Hope it is working for you. :D

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
That's badass man. You're awesome, thanks for helping me out. I would never of have guessed that it was necessary to add the .00 to 100 to make 100.00 to prompt decimals. Very nice. :)

****
Rep:
Level 83
You are welcome.
Haha. That confused me at 1st too. I was like, "Well my calculator can do decimals...why can't my program do it??".
But anyway, glad to help. :)

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Questionnnn!

Is there some way in call script to round a value to the nearest whole number? It doesn't matter if it's rounded up or down, just to a whole number in general.

*
A Random Custom Title
Rep:
Level 96
wah
You could try using the mod variable (%) function for decimal places and if it >=5, then you add 1 to the variable and if it's <5, then you do nothing.

Just an idea. :P

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Mod is for use by remainders. Like long devision. It's not a percent. Like 17/3 = 3 remainder of 2, therefore Mod 17 = 2. I actually did some research on how Mod works. It's basically useless all the time. lol

****
Rep:
Level 83
Umm...well I'll have to check to see if Ruby has a round feature. I'll be back when I find it.

I never have used Mod....its very limited in its uses.

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Let me know if these help, I understand what is happening, I don't know how to implement it in-game.

http://www.rpgmakervx.net/index.php?showtopic=4216 (I feel like this is very easy here)
http://www.ruby-forum.com/topic/90277
http://www.sitepoint.com/forums/showthread.php?t=646232

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
HOLY SHIT AWESOME. I fixed it myself!!

This is the code to round a variable to a whole number:
Code: [Select]
$game_variables[5] = 5.00
$game_variables[5] *= 0.25
$game_variables[5] = $game_variables[5].to_f
$game_variables[5] = $game_variables[5].to_i

the .to_f first converts the value to a floating number as a decimal and then the .to_i rounds it to an integer. I'm not certain as to why but you can't just do .to_i without first doing .to_f. :D :D

Source

****
Rep:
Level 83
Well thats good.
However I found two easier ways, and only one fits in the call script. Just do it
Code: [Select]
$game_variables[1]=$game_variables[1].round
Its easier and smaller. lol

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
Ooo, I like that, it beats having to write it so long. I'll check that out.

Edit: Oh, is it necessary to have the spaces between the variables and the = sign? looks like you don't have the spaces, i wasn't sure if it matters.
Tested, looks like it doesn't matter. cool
« Last Edit: November 15, 2009, 07:38:01 PM by grafikal »

****
Rep:
Level 83
I didn't put any spaces, but that's because it wouldn't fit on one line of the call script....which apparently it needs to. However, if it works for you with spaces, go for it