Switching language in module Vocab

Discussion in 'Learning Ruby and RGSSx' started by TheoAllen, Nov 19, 2013.

  1. IceDragon

    IceDragon Elder Cookie Dragon Veteran

    Messages:
    73
    Likes Received:
    60
    Location:
    Jamaica
    First Language:
    English
    Primarily Uses:
    N/A
    Just overwrite everything (its what I do, and I'm more productive that way)


    Sometimes you gotta break stuff to make it better, like a few bones and few noses when things won't go your way.


    Its even better ifs its just your project as well (you can get away by breaking as much compatability as you need to).


    I prefer foundation fixes rather than countless patches.


    If its broken at the core, then fix it at the core, the more you try to work around the problem is the more pronounced it becomes.


    oh boy there I go again ranting on. :x sowwy.


    Summary: Just replace all the constant calls with method calls, it may be a bit of work in the beginning but it will be well worth it.
     
    #21
  2. estriole

    estriole Veteran Veteran

    Messages:
    1,030
    Likes Received:
    334
    First Language:
    indonesian
    @icedragon: we can change default rtp script. but we might still have issues with 'other' people script. since i've seen some that use Vocab::Blablabla too in their script. it won't matter if this only concerning our project. but theo might want to create 'multi language' script and release it to public (in his community perhaps). it will cause that script could have lots of incompatibility with other scripter script(there's script by galv that have issues like that. i think the script that define unique actor stats vocab)... and since it's used by community... who knows what script they slap in their project. :D .
     
    #22
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,390
    Likes Received:
    4,961
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    No, I wouldn't go in that way if I planned to release script for public. What I'm trying is to make it has a high compatibility as possible. Since many scripts also reference in default script.
    But it's different matter if I'm working on my personal project. I don't care if someone breaking the encryption and steal my script. I might rewrite the core so they wont be compatible to other script (and I really did it).


    Well, just like estriole has mentioned
     
    #23
  4. IceDragon

    IceDragon Elder Cookie Dragon Veteran

    Messages:
    73
    Likes Received:
    60
    Location:
    Jamaica
    First Language:
    English
    Primarily Uses:
    N/A
    >_< FINE HAZ IT YOUR WAY *storms off, leaving a bit of code behind*

    Code:
    module Vocab  class << self    def const_missing(sym)      if respond_to?(sym)        send(sym)      else        super(sym)      end    end    def MyConst      "Hello World"    end  endendp Vocab::MyConst
    Code:
    module Vocab  MyConst = "Something"  const_set(:MyConst, "new_value")endp Vocab::MyConst
    I would avoid this method, since re-defining a constant is normally illegal. (Hence why its called a constant, without change), it raises a warning in ruby.
     
    Last edited by a moderator: Nov 21, 2013
    #24
    estriole likes this.
  5. estriole

    estriole Veteran Veteran

    Messages:
    1,030
    Likes Received:
    334
    First Language:
    indonesian
    yeah defining constant is normally illegal. it's the RM fault that use constant for vocab :D .

    but in their defense. they might not consider people wanting to change languages :D .

    hopefully next RM will use method for vocab so it can redefine easily :D .
     

    btw the first code is interesting... maybe we can define new method to replace the all the constant.

    first deleting all the constant used using

    remove_const:)CONSTANT)edit: wow we don't need to remove the constant at all :D . i didn't see that at first. i guess when we call constant it will go to const_missing method.first... nice...

    edit2: after more test we need to remove the constant first if the constant already exist:

    ex:

    module Vocab  MyConst = "test"  class << self    def const_missing(sym)      if respond_to?(sym)        send(sym)      else        super(sym)      end    end    def MyConst      "Hello World"    end  endendp Vocab::MyConstwill print "test"

    module Vocab  MyConst = "test"  remove_const:)MyConst)  class << self    def const_missing(sym)      if respond_to?(sym)        send(sym)      else        super(sym)      end    end    def MyConst      "Hello World"    end  endendp Vocab::MyConstwill print "Hello World"
     
    Last edited by a moderator: Nov 23, 2013
    #25

Share This Page