11-14-2012, 06:54 AM
Hello and good day!
I'm starting this thread as a sort of general discussion, but instead of flashing memes and making dick jokes we're going to discuss code (how fun!) Did you have a silly problem that, according to you, didn't make any damn sense? Did you figure it out afterwards and go "Duh"? Heck, do you have useful code snippets that you want to share, but don't feel like posting a Script / Support thread about it? That's what this thread is for!
Anywho, I'll share my silly code story of the day...
So I was testing Trickster's ATB when I kept coming across a silly error related to something that was in fact defined. Every time an actor levels up, I get this NoMethodError for level_up which is defined in Window_BattleStatus. "Strange," I said to the resident werewolf as he stared back at me, both of us puzzled. That's when I realized; I changed Window_BattleStatus from inheriting from Window_Base to inheriting from Window_Selectable, that way a cursor is over whomever is currently selecting actions.
"What does that have to do with anything," you ask?
Quite simply this...
Lesson Learned: Changing the inheritance of a predefined class in Ruby will cancel all of its unique methods, so you'll have to copy them over or re-write them.
I'm starting this thread as a sort of general discussion, but instead of flashing memes and making dick jokes we're going to discuss code (how fun!) Did you have a silly problem that, according to you, didn't make any damn sense? Did you figure it out afterwards and go "Duh"? Heck, do you have useful code snippets that you want to share, but don't feel like posting a Script / Support thread about it? That's what this thread is for!
Anywho, I'll share my silly code story of the day...
So I was testing Trickster's ATB when I kept coming across a silly error related to something that was in fact defined. Every time an actor levels up, I get this NoMethodError for level_up which is defined in Window_BattleStatus. "Strange," I said to the resident werewolf as he stared back at me, both of us puzzled. That's when I realized; I changed Window_BattleStatus from inheriting from Window_Base to inheriting from Window_Selectable, that way a cursor is over whomever is currently selecting actions.
"What does that have to do with anything," you ask?
Quite simply this...
Code:
# First, we make two parent classes, ParentA and ParentB.
class ParentA
end
class ParentB
end
# Now Child inherits from ParentA with the 'blah' method defined.
class Child < ParentA
def blah
p 'blah'
end
end
# Now we create the Child object and call the 'blah' method.
# This should result in no error and print 'blah'.
c = Child.new
c.blah
# Changing inheritance from ParentA to ParentB cancels the 'blah' method.
class Child < ParentB
end
# Now we create the Child object and call the 'blah' method.
# This results in an error, all defined methods have been cancelled.
c = Child.new
c.blah
Lesson Learned: Changing the inheritance of a predefined class in Ruby will cancel all of its unique methods, so you'll have to copy them over or re-write them.