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.

Figuring out what called a def?

Dko

Member

Hiyas. Ive been working on my code and when I run it I get an error in one of my Def's. The thing is Ive done nothing too recently that would seam to call it. So I have no clue what could be causing it. So I was wondering if anyone had any advice on how I could figure out what part of my code could of called it? Then I could have a better idea of whats causing the error.
 

Dko

Member

Caller function? Im not sure I know of that and Jaberwoky it wouldn't really help because Im asking for help on how I could solve the problem my self which could be very broad.
 

Dko

Member

I really don't think showing my code will help. I just need to know how to figure out what called it. But if you really need to see it here it is.
Code:
 #--------------------------------------------------------------------------
  # * Set Stamina (Stam)
  #     stam : new Stamina (STAM)
  #--------------------------------------------------------------------------
  def stam=(stam)
    @stam_plus += stam - self.stam
    @stam_plus = [[@stam_plus,  1].max, 99].min
  end

with the error
undefined method '-' for nil:NilClass
 
Tdata;191666 said:
The problem could be in the fact that you are using both += and - in on expression.
It shouldn't matter that Dko's code has both += and - in one expression. Somehow when the method is being called it is trying to set stamina to nil. This causes the local variable stam to be set to nil. Then when the subtraction operation is preformed it a no method error for subtraction occurs since the nil class doesn't have a - method. The problem is in what is calling the method. Right click and search for "stam =" in the code and post the methods that call it, Dko, when you have time.
 
Is good that you have resolved the problem, but what I was saying to do is:
Code:
  #--------------------------------------------------------------------------
  # * Set Stamina (Stam)
  #     stam : new Stamina (STAM)
  #--------------------------------------------------------------------------
  def stam=(stam)
    p caller
    @stam_plus += stam - self.stam
    @stam_plus = [[@stam_plus,  1].max, 99].min
  end
For your next problem like this, you can use caller function.

Sorry for no giving more information in the first post...
 

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