Ruby, RGSS & General Code Discussion
#1
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...

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.
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }


Messages In This Thread
Ruby, RGSS & General Code Discussion - by Kain Nobel - 11-14-2012, 06:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Possible means to speed up Bitmap TONE code? DerVVulfman 7 3,098 06-11-2023, 08:22 PM
Last Post: kyonides
   RGSS scripting dissections and explinations Siletrea 97 104,465 03-18-2019, 06:46 AM
Last Post: Siletrea
   Help iwth script (RGSS Player crash) Whisper 3 8,533 06-17-2017, 05:03 PM
Last Post: Whisper
  How can I use the cmd of "require" in rgss superegp 2 5,918 11-03-2015, 06:16 AM
Last Post: kyonides
   Custom Game_Event code lags too much! MechanicalPen 4 6,642 06-27-2013, 11:22 PM
Last Post: MechanicalPen
Question  RGSS stoped to work Chaos17 5 7,750 02-14-2013, 05:13 PM
Last Post: DerVVulfman
   [Request] Tut. for RGSS Eldur 9 11,929 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [RUBY] Depack Thread Problem Narzew 1 4,392 07-20-2012, 01:16 PM
Last Post: Narzew
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 4,231 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Quick RGSS question - switches Ravenith 2 5,633 08-23-2009, 11:23 AM
Last Post: Ravenith



Users browsing this thread: 1 Guest(s)