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.

Check if an method exist

Atoa

Member

Maybe i missing something, but i don't know to check in a method if it already exist.

What exactly i want?
I want in an method to check if this same method already exist.
Something like this
Code:
alias test_alias test

def test

  if "method test exist"

   value = test_alias

  else

   value = 0

  end

  #the rest of the method

end

i want that because i want to add an new stat in more than one script, and i want to check if the method that set the stat exist, if not it set the value to zero, that way these scripts can be fully compatible, but without needing to be used togther.
 
I think it's self.method_defined?:)methodname), replacing methodname with your method. At least, that turned up in the MACL when I searched for defined. Make sure to include the colon, it's important. Makes it a symbol or something, I don't remember exactly.
 

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