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.

[VX][Ruby?] undefined method '+' for nilNilClass on a 'something=' writer method

I am now writing another script, and encoutered something I don't understand. Fist here is the project containing the script. Its mains goal is to add some time (minutes) per step the party makes, and convert them tou hours, daus,etc..., and to be able to exploit those datas later.

http://www.mediafire.com/download.php?wdzjmn4mm0u

The proble is, when I make my first step in the game, I got the 'undefined method '+' for nilNilClass' at line 139. This line is 'minyte += minutes_per_step'. It seems the probleme comes from the 'minute=' methof; as if I write '@minute += minutes_per_step', I get no error. Although ther is no point in doing ths, as a direct access to the class variable doesn't update the hour, day, etc... as does the write method.

I also tried (among many other things...)
  'm = minute + minutes_per_step'
  'minute = m'
but in this case, although I got no error, the class variable weren'tupdated !!!

It seems I didn't understand something about class variables and their read/write method... Can someone help (or at least point me to a good Ruby manual) ?
 
I got the minutes to add properly by changing it to
Code:
self.minute += minutes_per_step
which I guess forced it to call the minute method. I'm assuming instead it was trying to use a local variable, but I don't know why it would do that. Anyway, when I walked a bit and got to 60 minutes the same problem happened with the hour change in the minute method, so you'll probably have to change all the ones like that (self.hour +=, self.day +=, etc)
 
I tried it the other way ('def self.minute=( val)'), but didn't imaigne this one ('self.minute += minutes_per_step'). Good idea   :thumb: , although it doesn't explain the phenomena... I though the 'self' qualifier was more implicite than that. But I come from a more structured language...

Also, I changed all lines where local write method are used in conjonction with an operator (you're right, it also appears avery hour, day, month and year), and it works fine.

But if someone has a definite explanation, the thread is still open.

edit: OK, you all noticided it was a thread, not a threat  :grin:
 

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