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.

[Resolved]include script in my new script Oo

Status
Not open for further replies.

jacman

Member

hello everybody,

well, i have finish my script (for seing gold in map) but I modified Scene_Map, and for give my script with somebody, i must say to him "modifiy that and that" but its not very simple.

Its for that i search a system to include just a part which interests me to make function the script.

i heard "alias" but i don't know how use it.

Can you help me please ???

thanks :)
 

Dko

Member

Well I must say this was VERY hard to read and understand. If your not native to English then I can understand. If not please, please! Proof read before hand.

I think I understand though for anyone else who wants to answer. He wants to know how Aliasing works.
 
Aliasing works by providing a new name for the old method to be overridden so that it can be called upon when needed. Example:

Code:
class Foo
  def attack_target(target)
    damage = self.atk - (target.def / 2)
    return damage
  end
end

test = Foo.new
Foo.attack_target(Game_Actor.new(0))     # => 128


class Foo
  alias jat_old_attack_target attack_target

  def attack_target(target, damage = nil)
    if damage == nil
      return jat_old_attack_target(target)
    else
      return damage
    end
  end
end

test = Foo.new
Foo.attack_target(Game_Actor.new(0))    #=> 128
Foo.attack_target(Game_Actor.new(1), 9999)    #=> 9999

The syntax for alias is:
alias new_name_for_old_method old_method_name

Once a method is aliased and overridden, you can call the old method by calling new_name_for_old_method. DO NOT call old_method_name unless your method is recursive (and safe).

Be aware that when you're aliasing old methods, you do not include the parameter fields.

Code:
class Person
  def go_home(where, how, when)
    ...
  end

  def home?
    return @where == 'Home'
  end
end

class Person
[COLOR=Red]  alias jat_old_go_home(where, how, when) go_home(where, how, when) <-- Error![/COLOR]  
end

class Person
  alias jat_old_go_home go_home
  alias jat_old_home? home?

  def go_home(where, how, when, why = nil)
    if why == nil
      jat_old_go_home(where, how, when)
    else
      ...
    end
  end

  def home?
    return ((jat_old_home?) and (@why.valid_reason?))
  end
end
 

jacman

Member

thanks :

- Dko, yes im not english, im french :) sorry, my bad

- jack, well i try your example, but it doesn't work, look :

Code:
class Window_Or < Window_Base
  def initialize
    super(0,-80,200,80)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    refresh
  end
  
  def refresh
    self.contents.clear
    cx = contents.text_size($data_system.words.gold).width
    self.contents.draw_text(0, -10, 100,  40, "Vous possédez :")
    self.contents.draw_text(60, 20, 100-cx-2, 20, $game_party.gold.to_s, 2)
    self.contents.draw_text(50-cx, 20, cx, 20, $data_system.words.gold, 2)
  end

  def update
      refresh
    end
  end
  
  class Scene_Map
    alias new_main main
    alias new_update update
    
    def main
      @fenetre = Window_Gold.new
      @active = 0
    end
      
    def update
      @fenetre.update
        if @active == 1
          if @fenetre.y != 0
              @fenetre.y += 2        
          end
      elsif @active == 0
          if @fenetre.y != -80
              @fenetre.y -= 2
          end
      end
    if Input.trigger?(Input::F8)
      if @active == 1
        @active = 0
      else
        @active = 1
      end
    end
  end
end

i try to insert my modif but it give me an error. In fact, i not very understand ':|
if you could learn me with my code it'll be very cool :please:

thanks a lot
 
You aliased the old methods but you didn't call any of them...
Also, aliasing makes the old methods OLD </4chan>, not NEW.

Code:
  class Scene_Map
    alias [COLOR=Red]old[/COLOR]_main main
    alias [COLOR=red]old[/COLOR]_update update
    
    def main
      @fenetre = Window_Gold.new
      @active = 0
[COLOR=red]      old_main
      @fenetre.dispose[/COLOR]
    end
      
    def update
      [COLOR=red]old_update[/COLOR]
      @fenetre.update
        if @active == 1
          if @fenetre.y != 0
              @fenetre.y += 2        
          end
      elsif @active == 0
          if @fenetre.y != -80
              @fenetre.y -= 2
          end
      end
    if Input.trigger?(Input::F8)
      if @active == 1
        @active = 0
      else
        @active = 1
      end
    end
  end
end
 
This topic has been resolved. If jacman or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

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