Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Convert Nil into String Errors...

Juuhou

Sponsor

I was wondering, what do these errors mean? And if I keep encountering one then how I would I go about fixing it?
 
This means that the variable, any kind(global '$', method '@', or local), is undefined. You are probably using draw_text and the string you are passing includes a variable that is undefined. I'd define it if I was you. It could very well be that you are defining the variable, but not until after it has already passed the draw_text method call. I would define it before then at least to empty string "". Another way around it is to have a simple if then statement like this...

Code:
if str != nil
   @sprite.bitmap.draw_text(x, y, width, height, str)
end

If you're not using the draw_text method, then find a line where you are condensing a string using a variable(s).
Hope that helps! Good luck!
 

Jared

Member

or simple
Code:
@sprite.bitmap.draw_text(x, y, width, height, str) if str
(because in Ruby everything, that is not nil or false, is interpreted as true)

Usually, only global variables and instance variables are nil. So search for this variables in your script and check, if the scriptline could call with a nil object. Also such lines could result in the error:
Code:
"My name is" + @name #@name is nil
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top