Help - Search - Members - Calendar
Full Version: Converting FixNum to String
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS
Rohiaw
Well I keep getting this error and i need to know how to do this. I know it can be done, coz if it cant, than RGSS wud be just plain useless ...

basically i have an integer:

number = 1

and i need to use it in a string, like so:

string = "Graphics\\Characters\\" + number + ".png"
(for example)

But i get an error saying I cant convert a FixNum into a string.

Any help ? :3
The Law G14
Ah, well what you have to do is use the to_s method which happens to be a method of the Integer class. The Help File defines the method as "Converts an integer to a base-10 string expression." So to keep it plain and simple, this "to_s" method converts your integer into a string, which seems to be what you're looking for.

So in effect, you would change this:

string = "Graphics\\Characters\\" + number + ".png"

To this:

string = "Graphics\\Characters\\" + number.to_s + ".png"

Then instead of looking for the actual Integer 1, it would look for the string "1". Hope this helps smile.gif
Rohiaw
Thanks. Exactly what i needed tongue.gif
Although i may have used this before ... hah biggrin.gif may have forgotten it.
thanks tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.