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.

Can't define methods within "File" class?

Good day everybody!

Earlier I was trying to define methods that aren't in the default File class, mainly ".copy", but after I defined it and tested it with an event's call script, it would pop a no method error... okay, so next I tried just screwing with default File class methods and overwritting them so I could get some stupid error, but nothing happened. For instance, I tried overwritting .delete() to print "Test", but... it didn't do anything.

Is there a reason I can't define methods in the File class? Here's my cheap example, which didn't do anything whatsoever when I tested it.

class File
  def delete(filename = "")
    p "All I do now is print a stupid message, I'm not even going to listen to your arguments."
  end
end

I've also tried creating a new module called File2, then include it in File, but that didn't help either.

Basically, what I'm needing for the File class is certain methods that aren't included in RPGXP, such as "cp" or "copy", and perhaps some other stuff I can't really think of off the top of my head right now, but I can't even define methods within the File class, it acts like the method isn't defined whatsoever when it really has been. Any particular reason why?
 

Zeriab

Sponsor

You have defined an instance method.
What you want is to define a class method.
Use def self.delete(filename = "") instead. (There are other ways as well, that's just the simplest)

*hugs*
- Zeriab
 

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