Dollars and Cents Script Code Snippet

Started by Reno-s--Joker, February 21, 2009, 12:34:46 am

Previous topic - Next topic

Reno-s--Joker

Here is a little code snippet thing that could be useful if you want to use dollars and cents format for your game:

Wherever you see:
self.contents.draw_text(x, y, width, height, @gold.to_s)

You can replace @gold.to_s with:
format("$%.2f", (@gold/100).to_s)


e.g. 300G becomes $3.00, 495059 gold becomes $4950.59.

Note that the above code treats 1 standard G as being 1 cent in dividing it by 100. This way, you can sell items for $9.99 like in the real shops! :V:

If you want whole dollars (which is kinda pointless) just change the code to:
format("$%.2f", @gold.to_s)


If you want to omit the $ sign, change to:
format("%.2f", (@gold/100).to_s)


Credits:
This Discussion on Ruby-Forum

Holyrapid

Nice. I may use this in my game ;) power up


RoseSkye

Quote from: Reno-s--Joker on April 02, 2009, 05:39:09 am
:) Thank you! I really appreciate it, and I'm glad you found it remotely useful!


*pets* Good boy *pets* Who wants a cookie? YOU DO! Who's an awesome scripter? YOU ARE!! *pets and rubs belly*

Reno-s--Joker

:3 Aww, thank you Rose! :D
I couldn't say I'm an awesome scripter just yet though. o_O Although I wish I was. ;___;

meyvn MaRa

August 20, 2009, 10:14:18 am #5 Last Edit: August 20, 2009, 10:19:06 am by meyvn MaRa
I know this might be necroposting, but I tried this script and it didn't work. When I start the game, it says something about line 24. It contains:
self.contents.font.color = system_color


I'm a n00b at scripting, so I don't know what's up with the script.

//Oh, and I'm using XP, not VX.

Aqua

Are you using the official RMXP or Dyna or PK or whatever it's called? xD

meyvn MaRa


fugibo

Quote from: meyvn MaRa on August 20, 2009, 10:14:18 am
I know this might be necroposting, but I tried this script and it didn't work. When I start the game, it says something about line 24. It contains:
self.contents.font.color = system_color


I'm a n00b at scripting, so I don't know what's up with the script.

//Oh, and I'm using XP, not VX.


First, make sure you have the scripts in the right order.

And if that doesn't fix it, post the actual error and the scripts you're using (in the order they are in the Script editor).

meyvn MaRa

August 23, 2009, 08:31:19 am #9 Last Edit: August 23, 2009, 08:33:11 am by meyvn MaRa
Right order? What do you mean "right order"? The instuctions say that all I have to do is to change a part of a line of a script called "Window_Gold".

Well, I'll post the script as how I wrote it:

#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Gold < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 160, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   cx = contents.text_size($data_system.words.gold).width
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s)
   self.contents.font.color = system_color
   self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
 end
end

meyvn MaRa

####   #        #  ##        ##  ####
#     #  #        #  #  #    #  #  #     #
####   #        #  #    ##    #  ####
#     #  #        #  #            #  #
####     ####    #            #  #

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

meyvn MaRa


Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

meyvn MaRa

Oh yeah, I forgot. But, the right order has nothing to do with this, 'cuz I only replaced a one line of a default script called "Window_Gold".

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

meyvn MaRa

Quote from: Blizzard on September 06, 2009, 04:41:05 am
No problem. Just making sure, lol!

:...:

Well, can anyone help me please? I'm a :n00b: at scripting, so I have no idea of what I'm suposed to do...

Jackolas

September 08, 2009, 02:47:18 am #17 Last Edit: September 08, 2009, 02:48:48 am by Jackolas
you did:
    self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s)


change it to:
    self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s))


remember that you have the same amount of ) as of (

meyvn MaRa

Now it gives me an error message of that line:

QuoteScript "Window_Gold" line 23: NoMethodError occured.

undefined mathed `/" for nil:NilClass

Jackolas

been looking at this for over an hour and i have the feeling that this Snippet will only apply to 1-2 specific menu systems.

the first reason i have for this is that in WHOLE rmxp "@gold.to_s" can not be found.
the only rule there can be found that seems close is: "self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)" in window_gold

so I want to know who got this 1 to work and if they can post there script.