[RESOLVED] Permanent Numbers=sprintf

Started by Jragyn, October 05, 2010, 04:19:36 pm

Previous topic - Next topic

Jragyn

October 05, 2010, 04:19:36 pm Last Edit: October 05, 2010, 05:21:38 pm by jragyn00
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
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Blizzard

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))

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.

Jragyn

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
A bright light can either illuminate or blind, but how will you know which until you open your eyes?