Sprite_Character, character = nil in initialize

● ARCHIVED · READ-ONLY
Started by TheoAllen 5 posts View original ↗
  1. I found this piece of code of initialize when working on Sprite_Character

    def initialize(viewport, character = nil) super(viewport) @character = character @balloon_duration = 0 update endBut I failed to understand why they put character = nil since obviously all update need the character not to be nil

    Seems there's a hidden message of this kind of design. Thought?
  2. Looks like an oversight. It requires a character.
  3. simply because all character need to be nil in begin...

    this never good to atribuate a value to something in a initialize 

    so normally the character will equal nil because they don't have anything to show.

    edit : and the update serve to atribuate something to the character!
  4. this never good to atribuate a value to something in a initialize
    If a constructor requires values, you should always make them required arguments.
  5. @Nio -

    simply because all character need to be nil in begin...

    this never good to atribuate a value to something in a initialize
    Doing this in the parameters

    def sample(param=value)Simply means that the value will be used in case you didn't pass the parameter, making the parameter optional instead of required. It is used by many methods in the default scripts.like

    def is_it_true(idk=true) return idkendif I just call is_it_true, it would return true, but if I call is_it_true(false) that will return false instead.If you look at the default scripts (I used the global search for any calls to Sprite_Character.new), all that creates a Sprite_Character object passes a character actually. If you didn't pass a character the update methods would actually fail and cause an error call as they are retrieving values from the character. And that is why it is weird that they made the character parameter as optional instead of required.