Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Jragyn on October 05, 2010, 04:19:36 pm

Title: [RESOLVED] Permanent Numbers=sprintf
Post by: Jragyn on October 05, 2010, 04:19:36 pm
In the instance of scripting, say somewhere simple like SP Cost of a skill...
How would I go about /always/ have 3 digits?

ie:

Heal costs 4 sp.
In the skill window, I'd like it to say '004'.

Fire2 costs 25 sp.
In the skill window, it should say '025'.

Ultima costs 180 sp/
In the skill window, it should say '180'.


How would this be possible?
I have a feeling its a lot more complex than the idea itself :\


--J
Title: Re: Permanent Numbers..?
Post by: Blizzard on October 05, 2010, 04:41:24 pm
You can use string-print-format instead of to_s.

sprintf("FORMAT", ...)


You can look up printf formatting on google. The particular format that you need is %03d which means that there always are 3 digits and that leading zeros should be added in case there are less than 3 digits in the number. An example of usage would look like this:

self.contents.draw_text(x, y, w, h, sprintf('%03d', skill_id))

Title: Re: Permanent Numbers..?
Post by: Jragyn on October 05, 2010, 05:18:14 pm
Ahha!
Ingenious.
I was unaware you could implant sprintf(asdfasdf) inside of draw_text.

Thank you kindly.

Yet again, Blizzard saves the day :P


--J