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.

MACL - Method and Class Library 2.3

Method and Class Library
Version 2.3

What is this?

This script set provides a utility for other scripters by: adding extra methods, classes & modules to prevent other scripters from "reinventing the wheel" and adding methods, classes & modules for other scripters to use. It also provides a set of commonly used constants so setup will not be as much as a hassle among scripts.


Installing the MACL 2.3

Simple copy and paste the MACL Complete text file from below into your game. Paste it below Scene_Debug. Make sure this is the first script after Scene_Debug unless you use the SDK, then put this directly after the SDK.

Files
MACL Complete Text File

What Can I do to Help?

If you have something you want to submit, then post here but read the section in the documentation on this topic. If you find a bug with any item in the library also post here. All of your help is appreciated.
 
Well, here it goes.

By the way that there is no fill version of these methods. I planned to do them later as they are slightly more complicated but in the end I chose to let it gather dust instead.

Note that the Bitmap#draw_ellipse method is actually a draw_polygon that, by default, draws a 30-sided polygon... but at 30 sides, it looks like a circle or an ellipse. Change the parameter to smaller values if you want something that looks like a polygon. Also, please leave the line_width parameter to its default value, which is 1. You will probably get sloppy results if you use another value. That parameter should be removed. (That, or the Bitmap#draw_line method, which is used "under-the-hood", should be recoded to round its extremities so it looks better.)

Ok, enough talk. Here is the script.
Code:
#==============================================================================

#******************************************************************************

#

# RGSS Extensions: Bitmap

# ----------------------------------------------------------------------------

# This script is an extension of the Bitmap class provided with RGSS. It

# allows to execute more vectorial and geometric operations, such as drawing

# lines, circles, rectangles, etc...

# 

# Note that all those operations are coded in Ruby, so if you heavily depend on

# those operations (if you redraw them on every frame, etc...), it might

# slowdown your game. The best, as always, is to draw only when necessary.

#

#                                                              by exseiken

#

#******************************************************************************

#==============================================================================

 

class Bitmap

  #----------------------------------------------------------------------------

  # draw_line: Draw a line between points (x1;y1) and (x2;y2) on the bitmap.

  #   x1: X-coordinate of an extremity of the line.

  #   y1: Y-coordinate of an extremity of the line.

  #   x2: X-coordinate of another extremity of the line.

  #   y2: Y-coordinate of another extremity of the line.

  #   color: The color of the line. It can support transparency.

  #   line_width: The width of the line in pixels. Set to 1 by default.

  #----------------------------------------------------------------------------

  def draw_line(x1, y1, x2, y2, color, line_width = 1)

    # calculate the dimensions vertically and horizontally

    cx = x2 - x1

    cy = y2 - y1

    

    # if the line is larger horizontally, draw it on an horizontal basis

    if cx.abs > cy.abs

      # if cx is 0, don't draw

      return if cx == 0

      

      # reorder the coordinates so that x1 is left of x2

      if x2 < x1

        temp = x2

        x2 = x1

        x1 = temp

        temp = y2

        y2 = y1

        y1 = temp

      end

      

      # draw the line

      for i in 0..cx.abs

        # calculate the position vertically

        y = y1 + cy * i / cx

        

        # draw the pixel

        set_pixel(x1 + i, y, color)

        

        # enlarge the line if the width is not 1

        if line_width != 1

          for j in 2..line_width

            # on even counter, draw higher; on odd draw below

            if (j & 1) == 0

              set_pixel(x1 + i, y - j / 2, color)

            else

              set_pixel(x1 + i, y + j / 2, color)

            end

          end

        end

      end

    else

      # if cy is 0, don't draw

      return if cy == 0

      

      # reorder the coordinates so that y1 is above y2

      if y2 < y1

        temp = x2

        x2 = x1

        x1 = temp

        temp = y2

        y2 = y1

        y1 = temp

      end

      

      # draw the line

      for i in 0..cy.abs

        # calculate the position horizontally

        x = x1 + cx * i / cy

        

        # draw the pixel

        set_pixel(x, y1 + i, color)

        

        # enlarge the line if the width is not 1

        if line_width != 1

          for j in 2..line_width

            # on even counter, draw left; on odd draw right

            if j & 1

              set_pixel(x - j / 2, y1 + i, color)

            else

              set_pixel(x + j / 2, y1 + i, color)

            end

          end

        end

      end

    end

  end

  

  #----------------------------------------------------------------------------

  # draw_square: Draw an unfilled square.

  #   rect: Rectangle corresponding to the square to draw.

  #   color: Color of the border.

  #   line_width: Width of the border. Set to 1 by default.

  #----------------------------------------------------------------------------

  def draw_square(rect, color, line_width = 1)

    draw_square(rect.x, rect.y, rect.cx, rect.cy, color, line_width)

  end

  

  #----------------------------------------------------------------------------

  # draw_square: Draw an unfilled square.

  #   x: X-coordinate of the top-left corner of the square.

  #   y: Y-coordinate of the top-left corner of the square.

  #   width: Width of the square.

  #   height: Height of the square.

  #   color: Color of the border.

  #   line_width: Width of the border. Set to 1 by default.

  #----------------------------------------------------------------------------

  def draw_square(x, y, width, height, color, line_width = 1)

    # draw the left side

    fill_rect(x, y, line_width, height, color)

    

    # draw the top side

    fill_rect(x, y, width, line_width, color)

    

    # draw the right side

    fill_rect(x + width - line_width + 1, y, line_width, height, color)

    

    # draw the bottom side

    fill_rect(x, y + height - line_width + 1, width, line_width, color)

  end

  

  #----------------------------------------------------------------------------

  # draw_ellipse: Draw an unfilled ellipse. (oval)

  #   ox: X-coordinate of the center of the ellipse.

  #   oy: Y-coordinate of the center of the ellipse.

  #   vradius: The vertical radius.

  #   ratio: Ratio between the vertical radius and the horizontal radius.

  #            (horizontal / vertical) Set it to 1.0 to draw a circle.

  #   color: Color of the border.

  #   line_width: Width of the border. Set to 1 by default.

  #   sides: The ellipse is in fact an elliptic polygon with a given amount of

  #            faces. For example, set it to 6 to have an hexagon. This is set

  #            to 32 by default, which is plenty to make it look like a curved

  #            form.

  #----------------------------------------------------------------------------

  def draw_ellipse(ox, oy, vradius, ratio, color, line_width = 1, sides = 32)

    # calculate the horizontal radius

    hradius = (vradius * ratio).to_i

    

    # set the initial coordinate

    x1 = ox

    y1 = oy - vradius

    

    # draw each side of the polygon except the last

    for i in 1...sides

      # calculate the position of the new point

      x2 = ox - (hradius * Math.sin(i * Math::PI * 2 / sides)).round

      y2 = oy - (vradius * Math.cos(i * Math::PI * 2 / sides)).round

      

      # draw a the line

      draw_line(x1, y1, x2, y2, color, line_width)

      

      # store the old position

      x1 = x2

      y1 = y2

    end

    

    # draw the last side

    draw_line(x1, y1, ox, oy - vradius, color, line_width)

  end

end

 

PS: I wrote this long before the legal English version was released, so I apologize if the comments are non-standard.
 
I haven't had much time to go and search for everything I made but I can already post one bitmap method :

Code:
#============================================================================== 
# ** RGSS Extensions: Bitmap
#-----------------------------------------------------------------------------
#    The Bitmap Class
#==============================================================================
class Bitmap
  #-------------------------------------------------------------------------
  # * Name:      Erase
  #   Info:      This method clears a part of the bitmap
  #   Author:    Selwyn
  #   Call Info: One or Four arguments, One Argument : Rect ; Four arguments : Integers
  #     One Arg  : Rect.new(x, y, width, height)
  #     Four Args : x, y, width, height
  #   Returns : nil
  #   Comments:  works the same as the build-in method 'clear' but only for a portion of the bitmap
  #-------------------------------------------------------------------------
  def erase(*args)
    if args.size == 1
      rect = args
    elsif args.size == 4
      rect = Rect.new(*args)
    end
    fill_rect(rect, Color.new(0, 0, 0, 0))
  end
end
 
Here are some methods I've been working on recently. I created an Math.root method based on the Nth Root Algorithm and a plus-minus function. Since both these method return arrays, I added arithmetic operators to the array class. In addition, I modified the Array class' [] and []= methods. If called with a range as the key, they will now read all values and write to all indexes inside the range.

Code:
#==============================================================================
# ** Math Module
#==============================================================================
module Math
  #-------------------------------------------------------------------------
  #   Name:      Nth Root
  #   Info:      Finds the nth root
  #   Author:    Icarus Featherfight
  #   Call Info: Numeric nth and other
  #   Returns:   An interger of the nth root rounded to the nearest whole number
  #   Example:   Math.√ 3, 729 => 9
  #-------------------------------------------------------------------------
  def Math.root(n, other, both = false)
    return nil if other < 0 and n % 2 == 0
    case n
    when 0
      raise ZeroDivisionError, "You cannot find the zeroith root of a number"
    when 1
      return other
    when 2
      return both ? [sqrt(other), -(sqrt(other))] : sqrt(other)
    else
      # Make an initial guess
      g = 15
      if other < g**n and (g**n - other).abs > ((g-5)**n - other).abs
        g -= 5
      elsif other > g**n and (g**n - other).abs > ((g+5)**n - other).abs
        g += 5
      end
      # Return if the guess is now correct
      return (n % 2 == 0 && both ? [g, -g] : g) if other == g**n
      # If not, refine the guess...
      if other < (g.√ 2)**n
        g = g.√ 2
      elsif other > g**2**n
        g **= 2
      end
      # and use nth root algorithm to iteratively find the nth root x
      x = [g.to_f]
      until x[-2] != nil and (x[-2]*100_000).round == (x[-1]*100_000).round
        x.push 1.to_f/n * ((n-1).to_f * x[-1] + other.to_f / x[-1]**(n-1))
      end
      x = x.pop.round
      return n % 2 == 0 && both ? [x, -x] : x
    end
  end
end
Code:
#==============================================================================
# ** Numeric
#==============================================================================
class Numeric
  #-------------------------------------------------------------------------
  #   Name:      ? (plus-minus)
  #   Info:      Both adds and subtacts
  #   Author:    Icarus Featherfight
  #   Call Info: One Argument: other
  #   Returns:   An array of both the addition and the subtraction values
  #   Example:   4.? 7 => [11, -3]
  #-------------------------------------------------------------------------
  def ?(other)
    return [self + other, self - other]
  end
  #-------------------------------------------------------------------------
  #   Name:      Nth Root
  #   Info:      Finds the nth root
  #   Author:    Icarus Featherfight
  #   Call Info: A Numeric other
  #   Returns:   An interger of the nth root rounded to the nearest whole number
  #   Example:   3.√ 729 => 9
  #              3.root 729 => 9
  #-------------------------------------------------------------------------
  def √(other)
    return Math.root(self, other)
  end
  alias_method :root, :√
end
Code:
=begin
============================================================================== 
 ** Array.math
------------------------------------------------------------------------------
Description:
------------
  More Mathematical methods for the Array class. These methods however assume
  all objects in the array are of class Numeric.
  
Method List:
------------
  Arithmetic operators (+, -, ?, *, /, **, √)
==============================================================================
=end
class Array
  #-------------------------------------------------------------------------
  #   Names:     Arithmetic operators (+, -, ?, *, /, %, **, √)
  #   Info:      Preforms basic mathamatical operations on the array
  #   Author:    Icarus Featherfight
  #   Call Info: A Numeric other
  #   Returns:   The Array self with each element modified
  #   Examples:  [6, 2, 4] + 1      =>  [7, 3, 5]
  #              [0, 3, 2] - 1      =>  [-1, 2, 1]
  #              [5, 6, 3].? 2      =>  [[7, 3], [8, 4], [5, 1]]
  #              [9, 1, 7] * 3      =>  [27, 3, 21]
  #              [6, 12, 9] / 3     =>  [2, 4, 3]
  #              [3, 5, 10] ** 3    =>  [27, 125, 1000)
  #              [25, 4, 9].√ 2     =>  [5, 2, 3]
  #              [25, 4, 9].root 2  =>  [5, 2, 3]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_add, :+
  def +(other)
    if other.is_a? Numeric
      result = [] 
      self.each_index {|index| result[index] = self[index] + other}
      return result
    else
      icarus_macl_add(other)
    end
  end
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_subtract, :-
  def -(other)
    if other.is_a? Numeric
      result = [] 
      self.each_index {|index| result[index] = self[index] - other}
      return result
    else
      icarus_macl_subtract(other)
    end
  end
  #-------------------------------------------------------------------------
  def ?(other)
    result = [] 
    self.each_index {|index| result[index] = self[index].? other}
    return result
  end
  #-------------------------------------------------------------------------
  def *(other)
    result = [] 
    self.each_index {|index| result[index] = self[index] * other}
    return result
  end
  #-------------------------------------------------------------------------
  def /(other)
    result = [] 
    self.each_index {|index| result[index] = self[index] / other}
    return result
  end
  #-------------------------------------------------------------------------
  def %(other)
    result = [] 
    self.each_index {|index| result[index] = self[index] % other}
    return result
  end
  #-------------------------------------------------------------------------
  def **(other)
    result = [] 
    self.each_index {|index| result[index] = self[index] ** other}
    return result
  end
  #-------------------------------------------------------------------------
  def √(nth)
    result = [] 
    self.each_index {|index| result[index] = other.√ self[index]}
    return result
  end
  alias_method :root, :√
end
Code:
#==============================================================================
# ** Array
#==============================================================================
class Array
  #-------------------------------------------------------------------------
  #   Name:      []
  #   Info:      Modifies [key] when key is a range expression
  #              Return an array of indexed values within the range 
  #   Author:    Icarus Featherfight
  #   Example:   @data = [6, nil, true, 'max', 4]
  #              p @data[-1..2] => [4, 6, true]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_index, :[]
  def [](key)
    if key.is_a? Range
      array = []
      for index in key do array << self[index] end
      return array
    else
      icarus_macl_index(key)
    end
  end
  #-------------------------------------------------------------------------
  #   Name:      []=
  #   Info:      Modifies [key]=(value) when key is a range expression
  #              Sets each index within the key (range) to value
  #   Author:    Icarus Featherfight
  #   Example:   @data = []
  #              @data[1..5] = 2
  #              p @data => [nil, 2, 2, 2, 2, 2]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_indexequals, :[]=
  def []=(key, value)
    if key.is_a? Range
      for index in key do self[index] = value end
    else
      icarus_macl_indexequals(key, value)
    end
  end
end
Hopefully, they will make a valuable addition to the MaCL. :)
 
Code:
=begin
============================================================================== 
 ** unsort
------------------------------------------------------------------------------
Description:
------------
  this method can unsort all types of Enumerable

Class List:
-----------
  Enumerable
  Array

Method List: (avaiable for all classes)
------------
  unsort

==============================================================================
=end

module Enumerable
  #-------------------------------------------------------------------------
  #   Name      : unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info : with no Arguments
  #   Comments  : can make nosense with strings
  #-------------------------------------------------------------------------
  def unsort
    Array.unsort(self.entries)
  end
end

class Array
  #-------------------------------------------------------------------------
  #   Name      : self.unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info :  with min one Argument from type can this be everything
  #-------------------------------------------------------------------------
	def self.unsort(*arrays)
		array = arrays.flatten
		Array.new(array.size) {
			zufall = rand(array.size)
			array.delete_at(zufall)
		}
	end
  #-------------------------------------------------------------------------
  #   Name      : unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info : with no Arguments
  #-------------------------------------------------------------------------
	def unsort
		self.class.unsort(self)
	end
end
Code:
=begin
============================================================================== 
 ** Range.sort
------------------------------------------------------------------------------
Description:
------------
  with this you can sort Ranges

Class List:
-----------
  Range

Method List: 
------------
  <=>

==============================================================================
=end

class Range
  include(Comparable)
  def <=>(other)
    temp = first <=> other.first
    temp = last <=> other.last if temp = 0
    return temp
  end
end
i hope this are in the right form


EDIT:
Code:
  #-------------------------------------------------------------------------
  # * Name      : To HSB
  #   Info      : Converts to Hue, Saturation, and Brightness
  #               returns an array setup like so: [hue, sat, bright]
  #   Author    : Trickster
  #   Call Info : No Arguments
  #-------------------------------------------------------------------------
  def to_hsb
    return self.class.to_hsb(red, green, blue)
  end
this is shorter then yours (why write the code double)
 
Calibre;255946":eo3juolk said:
In my demo, I have just had an error reported that won't allow the game to load. So many other people have loaded it fine though, can you spot the reason?

"Script 'Method & Class Library' line 47: LoadError occured.
No such file to load--Array_2D.rb"

uhh it seems to me that you are using an older version please update to version 2.1

Korin;256507":eo3juolk said:
I get an error at 4261 - Stack Level too deep.

It doesn't help anyone if you don't post the line that causes the error
 
Ok Trickster, I see now that my original submissions are redundant. This time however I added to the Table class and scripted a descendant Object_Table class. It stores the objects numerical id then retrieves the original object using the included module ObjectSpace's _id2ref method. However, since object ids are often greater than 32,767 I had to create a secondary Table to properly store the values. So, what's the verdict on this one?

Code:
#==============================================================================
# ** RGSS.Table
#------------------------------------------------------------------------------
# Description:
# ------------
# Adds new features to the Table class. [] and []= methods now accept
# coordinate key arrays and negative coordinate indexes. It also adds
# iteration methods, the Enumerable module and several miscellaneous methods
# all objects in the array are of class Numeric.
#
# Modified Methods:
# -----------------
# initialize
# []
# []=
# _dump
# self._load
#
# Methods Added:
# ------------
# Enumerable (see below)
# each
# each_coordinates
# each_with_coordinates
# coordinates
# each_index
# index
# clear
# nitems
# compact
# compact!
# plane
# column
# row
#==============================================================================
#==============================================================================
# ** Table
#==============================================================================
class Table
  #-------------------------------------------------------------------------
  # Include 
  # * Names     : all?, any?, collect, map, each_with_index,  find, detect,
  #               find_all, select, grep, inject, member?, include?, max,
  #               min, partition, reject, sort, sort_by, to_a, entries, zip
  #-------------------------------------------------------------------------  
  include Enumerable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :negitive_read            # allow negitive index reading?
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias_method :icarus_table_initialize, :initialize
  def initialize(*args)
    icarus_table_initialize(*args)
    # Default value for negitive index reading
    @negitive_read = true
    # Store number of axis for each coordinate method
    @axis = args.size
  end
  #-------------------------------------------------------------------------
  # * []
  #-------------------------------------------------------------------------
  alias_method :icarus_table_nth, :[]
  def [](*args)
    # Remove nil arguments from the end of the array 
    args.delete_at(-1) while args[-1].nil?
    # If negitive reading is enabled
    if @negitive_read
      # Modify arguments if they are negative indexes
      args[0] += self.xsize unless                 args[0] >= 0
      args[1] += self.ysize unless args[1].nil? or args[1] >= 0
      args[2] += self.zsize unless args[2].nil? or args[2] >= 0
    end
    # Call original method with modified arguments
    return icarus_table_nth(*args)
  end
  #-------------------------------------------------------------------------
  # * []=
  #-------------------------------------------------------------------------
  alias_method :icarus_table_nthequals, :[]=
  def []=(*args)
    # Modify arguments if they are negative indexes
    args[0] += self.xsize unless                 args[0] >= 0
    args[1] += self.ysize unless args[2].nil? or args[1] >= 0
    args[2] += self.zsize unless args[3].nil? or args[2] >= 0
    # Call original method with modified arguments
    icarus_table_nthequals(*args)
  end
  #-------------------------------------------------------------------------
  # * _dump
  #-------------------------------------------------------------------------
  alias_method :icarus_table_dump, :_dump
  def _dump(i)
    return icarus_table_dump(i) + '~~' +
           Marshal.dump(@negitive_read) + '~~' + Marshal.dump(@axis)
  end
  #-------------------------------------------------------------------------
  # * self._load
  #-------------------------------------------------------------------------
  class << self
    alias_method :icarus_table_load, :_load
  end
  def self._load(string)
    array = string.split('~~')
    table = self.icarus_table_load(array[0])
    unless array[1].nil?
      table.instance_variable_set(:@negitive_read, Marshal.load(array[1]))
      table.instance_variable_set(:@axis, Marshal.load(array[2]))
    end
    return table
  end
  #-------------------------------------------------------------------------
  # * Name      : Each
  #   Info      : Iterates through all coordinates, yielding each value
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : Provides the basis for included Enumerable methods
  #-------------------------------------------------------------------------
  def each
    each_coordinates{|key| yield self[*key]}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Coordinates
  #   Info      : Iterates through all coordinates in the table
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : See Each or Coordinates methods for proper block setup
  #-------------------------------------------------------------------------
  def each_coordinates
    for x in 0...self.xsize
      if @axis == 1
        yield [x]
      else
        for y in 0...self.ysize
          if @axis == 2
            yield [x, y]
          else
            for z in 0...self.zsize
              yield [x, y, z]
            end
          end
        end
      end
    end
    return nil
  end
  #-------------------------------------------------------------------------
  # * Name      : Each With Coordinates
  #   Info      : Iterates through table, yielding each value and key
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def each_with_coordinates
    each_coordinates{|key| yield (self[*key], key)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Coordinates
  #   Info      : Finds the first coordinates to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def coordinates(value)
    each_coordinates{|key| return key if self[*key] == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Index
  #   Info      : Iterates through all indexes in a table array
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #-------------------------------------------------------------------------
  def each_index
    self.to_a.each_index{|index| yield(index)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Index
  #   Info      : Finds the first index to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def index(value)
    each_with_index{|val, index| return index if val == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    # Reset table
    if self.ysize == 1    then initialize(self.xsize)
    elsif self.zsize == 1 then initialize(self.xsize, self.ysize)
    else                       initialize(self.xsize, self.ysize, self.zsize)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : NItems
  #   Info      : Iterates through index, counting all non-zero elements
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def nitems
    n = 0
    each{|value| n += 1 unless value == false}
    return n
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact
  #   Info      : Returns a new table with nil elements removed from positive
  #               extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact
    return self.dup.compact!
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact!
  #   Info      : Removes nil elements from positive extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact!
    if self.zsize == 1
      x = self.xsize
      y = self.ysize
      x -= 1 while row(x - 1).all?{|item| item.nil?} && x > 1
      y -= 1 while column(y - 1).all?{|item| item.nil?} && y > 1
      resize(x, y)
    else
      planes = []
      for z in 0...self.zsize
        planes[z] = plane(z).compact!
      end
      planes.delete_at(-1) while planes[-1].all?{|item| item.nil?}
      xmax, ymax = 1, 1
      planes.each{|table|
                  xmax = table.xsize if xmax < table.xsize
                  ymax = table.ysize if ymax < table.ysize
                  }
      resize(xmax, ymax, planes.size)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : Plane
  #   Info      : On a 3D table returns the 2D plane at z value
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical z
  #-------------------------------------------------------------------------
  def plane(z)
    return if self.ysize == 1 || self.zsize == 1 || z.nil? || z >= self.zsize
    if self.class == Object_Table
      plane = Object_Table.new(self.xsize, self.ysize)
    else
      plane = Table.new(self.xsize, self.ysize)
    end
    for x in 0...self.xsize
      for y in 0...self.ysize
        plane[x, y] = self[x, y, z]
      end
    end
    return plane
  end
  #-------------------------------------------------------------------------
  # * Name      : Column
  #   Info      : On a 3D or 2D table returns the array at y and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical y and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def column(x, z = nil)
    column = []
    for y in 0...self.ysize
      column[y] = self[x, y, z]
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Row
  #   Info      : On a 3D or 2D table returns the array at x and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical x and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def row(y, z = nil)
    row = []
    for x in 0...self.xsize
      row[x] = self[x, y, z]
    end
  end
end
Code:
#==============================================================================
# ** Object Table                                        By Icarus Featherfight
#------------------------------------------------------------------------------
#  The multidimensional array class; extended to hold objects.
#   - when resizing table, all data from before the size change is retained
#==============================================================================
class Object_Table < Table
  #-------------------------------------------------------------------------
  # Include ObjectSpace
  # * Names     : _id2ref, define_finalizer, each_object, garbage_collect,
  #               undefine_finalizer 
  #-------------------------------------------------------------------------  
  include ObjectSpace
  #-------------------------------------------------------------------------
  # * Name      : Initialize
  #   Info      : Creates main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #-------------------------------------------------------------------------
  def initialize(*args)
    super
    # Creates depth table
    @depth = Table.new(*args)
    # Initialize table with nil values
    self.each_coordinates{|key| self[*key] = nil}
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Reference
  #   Info      : Extends method to return objects; stored as ids
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments or one coordinate key array
  #   Comments  : Prevents ArgumentErrors when using a coordinate key array
  #-------------------------------------------------------------------------
  def [](*args)
    # Abort if coordinates are outside of table
    return nil if super.nil?
    # Returns original object after recalculating its id
    return _id2ref(super + (32_768 * @depth[*args]))
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Assignment
  #   Info      : Extends method to store an objects id
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments or array and value
  #   Comments  : Prevents ArgumentErrors when using a coordinate key array
  #-------------------------------------------------------------------------
  def []=(*args)
    # Free current contents for GC
    a = args.dup
    a.pop
    undefine_finalizer(self[*a]) unless self[*a] == false
    # Define finalizer to prevent GC
    define_finalizer(args[-1], proc {|id| p "Object Table Entry: #{id}" })
    # Replace object with its id
    args[-1] = args[-1].id
    # Create key for secondary depth table
    key = args.dup
    key.pop
    # Store depth and reduce id integer to effective range of table
    @depth[*key] = args[-1] / 32_768
    args[-1] %= 32_768
    # Store modified object id value
    return super(*args)
  end
  #-------------------------------------------------------------------------
  # * Name      : _dump
  #   Info      : Marshals Object_Table data
  #   Author    : Icarus Featherfight
  #   Call Info : An Interger i
  #   Comments  : Adds @depth Table to dump
  #-------------------------------------------------------------------------
  def _dump(i)
    return super(i) + '~|~' + Marshal.dump(@depth)
  end
  #-------------------------------------------------------------------------
  # * Name      : self._load
  #   Info      : Retores Object_Table from a marshaled string
  #   Author    : Icarus Featherfight
  #   Call Info : A String string
  #   Comments  : Restores @depth Table
  #-------------------------------------------------------------------------
  def self._load(string)
    array = string.split('~|~')
    table = super(array[0])
    table.instance_variable_set(:@depth, Marshal.load(array[1]))
    return table
  end
  #-------------------------------------------------------------------------
  # * Name      : Resize
  #   Info      : Resizes main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #   Comments  : All data from before the size change is retained
  #-------------------------------------------------------------------------
  def resize(*args)
    # Resize main table
    super
    # Resize depth table
    @depth.resize(*args)
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    self.each{|obj| undefine_finalizer(obj)}
    super
  end
  #-------------------------------------------------------------------------
  # * Name      : Expand
  #   Info      : Returns the tables array with nested arrays expanded
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def expand
    array = self.to_a
    array.each_index{|i| array[i, 1] = array[i] if array[i].class == Array}
    return array
  end
end
P.S. I know Selwyn already created Array_2D and Table_Object classes for the MaCL but his were based on the Array class.
As it turns out, the above code suffers from a critical oversight. Since all objects are disposed on exit, saving only their ids is not enough. The version below fixes this and is based on the array class.

#==============================================================================
# ** Object Table By Icarus Featherfight
#------------------------------------------------------------------------------
# The multidimensional array class; can hold all objects.
# - when resizing table, all data from before the size change is retained
# - negative coordinate indexes can be used
# - includes the Enumerable module
#==============================================================================
class Object_Table
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :negative_read # allow negative index reading?
attr_reader :data # data array
attr_reader :xsize, :ysize, :zsize # numerical coordinate maximums
#-------------------------------------------------------------------------
# * Name : Initialize
# Info : Initializes Object_Table
# Author : Icarus Featherfight
# Call Info : 1..3 Numeric coordinate maximums (xsize[, ysize[, zsize]])
#-------------------------------------------------------------------------
def initialize(*args)
# Store number of axis and axial maximums
@axis = args.size
@xsize, @ysize, @zsize = args[0], args[1], args[2]
# Create data table array
@data = []
if @axis >= 2
for x in 0...@xsize
@data 
 
Question:
are you think that defs for even and odd can be useful?

EDIT:

there is that:

Code:
Class Numeric
  #-------------------------------------------------------------------------
  #   Name      : Even?
  #   Info      : Return true if number is even
  #   Author    : Hanmac
  #   Call Info : zero(optimal) (says if zero is even)
  #-------------------------------------------------------------------------
  def even?(zero=true)
   return false if self.is_a?(Float)
   return zero if zero?
   return self % 2 == 0
  end
  #-------------------------------------------------------------------------
  #   Name      : Odd?
  #   Info      : Return true if number is odd
  #   Author    : Hanmac
  #   Call Info : No Arguments
  #-------------------------------------------------------------------------
  def odd?
   return false if self.is_a?(Float)
   return self % 2 == 1
  end
 
As it turns out, my first Object_Table suffered from a critical oversight. Since all objects are disposed on exit, saving only their ids is not enough. The version below fixes this and is based on a nested @data array. What do you think?

Code:
#==============================================================================
# ** Object Table                                        By Icarus Featherfight
#------------------------------------------------------------------------------
#  The multidimensional array class; can hold all objects.
#   - when resizing table, all data from before the size change is retained
#   - negative coordinate indexes can be used
#   - includes the Enumerable module
#==============================================================================
class Object_Table
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :negative_read            # allow negative index reading?
  attr_reader   :data                     # data array
  attr_reader   :xsize, :ysize, :zsize    # numerical coordinate maximums
  #-------------------------------------------------------------------------
  # * Name      : Initialize
  #   Info      : Initializes Object_Table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 Numeric coordinate maximums (xsize[, ysize[, zsize]])
  #-------------------------------------------------------------------------
  def initialize(*args)
    # Store number of axis and axial maximums
    @axis = args.size
    @xsize, @ysize, @zsize = args[0], args[1], args[2]
    # Create data table array
    @data = []
    if @axis >= 2
      for x in 0...@xsize
        @data[x] = []
      end
      if @axis == 3
        for x in 0...@xsize
          for y in 0...@ysize
            @data[x][y] = []
          end
        end
      end
    end
    # Default value for negative index reading
    @negative_read = true
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Reference
  #   Info      : Returns Object stored at coordinates
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 Numeric coordinate arguments
  #-------------------------------------------------------------------------
  def [](*args)
    # Raise ArgumentError if there is the wrong number of arguments
    raise ArgumentError if args.size != @axis
    # Return nil if negative reading is disabled and a coordinate is negative
    return nil if @negative_read == false and args.any?{|num| num < 0}
    # Return Object stored at coordinates
    case @axis
    when 1
      return @data[args[0]]
    when 2
      return nil if @data[args[0]].nil?
      return @data[args[0]][args[1]]
    when 3
      return nil if @data[args[0]].nil? or @data[args[0]][args[1]].nil?
      return @data[args[0]][args[1]][args[2]]
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Assignment
  #   Info      : Stores Object at designated coordinates
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments and a Object value
  #-------------------------------------------------------------------------
  def []=(*args)
    # Raise ArgumentError if there is the wrong number of arguments
    raise ArgumentError if args.size - 1 != @axis
    # Raise IndexError if coordinates are out of range
    raise IndexError    if                   args[0] >= @xsize or
                           args[1] != nil && args[1] >= @ysize or
                           args[2] != nil && args[2] >= @zsize
    # Store Object at coordinates
    case @axis
    when 1
      return @data[args[0]]                   = args[-1]
    when 2
      return @data[args[0]][args[1]]          = args[-1]
    when 3
      return @data[args[0]][args[1]][args[2]] = args[-1]
    end
  end
  #-------------------------------------------------------------------------
  # Include 
  # * Names     : all?, any?, collect, map, each_with_index,  find, detect,
  #               find_all, select, grep, inject, member?, include?, max,
  #               min, partition, reject, sort, sort_by, to_a, entries, zip
  #-------------------------------------------------------------------------  
  include Enumerable
  #-------------------------------------------------------------------------
  # * Name      : Each
  #   Info      : Iterates through all coordinates, yielding each value
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : Provides the basis for included Enumerable methods
  #-------------------------------------------------------------------------
  def each
    each_coordinates{|key| yield self[*key]}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Coordinates
  #   Info      : Iterates through all coordinates in the table
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : See Each or Coordinates methods for proper block setup
  #-------------------------------------------------------------------------
  def each_coordinates
    for x in 0...@xsize
      if @axis == 1
        yield [x]
      else
        for y in 0...@ysize
          if @axis == 2
            yield [x, y]
          else
            for z in 0...@zsize
              yield [x, y, z]
            end
          end
        end
      end
    end
    return nil
  end
  #-------------------------------------------------------------------------
  # * Name      : Each With Coordinates
  #   Info      : Iterates through table, yielding each value and key
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def each_with_coordinates
    each_coordinates{|key| yield (self[*key], key)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Coordinates
  #   Info      : Finds the first coordinates to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def coordinates(value)
    each_coordinates{|key| return key if self[*key] == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Index
  #   Info      : Iterates through all indexes in a table array
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #-------------------------------------------------------------------------
  def each_index
    self.to_a.each_index{|index| yield(index)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Index
  #   Info      : Finds the first index to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def index(value)
    each_with_index{|val, index| return index if val == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    initialize(@xsize, @ysize, @zsize)
  end
  #-------------------------------------------------------------------------
  # * Name      : Resize
  #   Info      : Resizes main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #   Comments  : All data from before the size change is retained
  #-------------------------------------------------------------------------
  def resize(*args)
    # Abort if new dimentions equal the old
    return if args[0] == @xsize and args[1] == @ysize and args[2] == @zsize
    # Destroy axis
    if args[1].nil?
      case @axis
      when 2
        # Destroy y axis
        for x in 0...@xsize
          @data[x] = @data[x][0]
        end
      when 3
        # Destroy y and z axis
        for x in 0...@xsize
          @data[x] = @data[x][0][0]
        end
      end
      @axis = 1
      @ysize, @zsize = nil, nil
    elsif args[2].nil?
      if @axis = 3
        # Destroy z axis
        for x in 0...@xsize
          for y in 0...@ysize
            @data[x][y] = @data[x][y][0]
          end
        end
      end
      @axis = 2
      @zsize = nil
    end
    # Resize x axis
    if args[0] < @xsize
      # Crop table
      for x in args[0]...@xsize
        @data.delete_at(x)
      end
    elsif args[0] > @xsize and @axis >= 2
      # Extend table
      for x in @xsize...args[0]
        @data[x] = []
      end
      if @axis == 3
        for x in @xsize...args[0]
          for y in @ysize...args[1]
            @data[x][y] = []
          end
        end
      end
    end
    return if @axis == 1
    # Resize y axis
    if args[1] < @ysize
      # Crop table
      for x in 0...args[0]
        for y in args[1]...@ysize
          @data[x].delete_at(y)
        end
      end
    elsif args[1] > @ysize and @axis == 3
      # Extend table
      for x in @xsize...args[0]
        for y in @ysize...args[1]
          @data[x][y] = []
        end
      end
    end
    return if @axis != 3
    # Resize z axis
    if args[2] < @zsize
      # Crop table
      for x in 0...args[0]
        for y in args[1]...@ysize
          for z in args[2]...@zsize
            @data[x][y].delete_at(z)
          end
        end
      end
    elsif args[2] > @zsize
      # Extend table
      for x in @xsize...args[0]
        for y in @ysize...args[1]
          @data[x][y] = []
        end
      end
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : NItems
  #   Info      : Iterates through index, counting all non-zero elements
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def nitems
    n = 0
    each{|value| n += 1 unless value == false}
    return n
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact
  #   Info      : Returns a new table with nil elements removed from positive
  #               extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact
    return self.dup.compact!
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact!
  #   Info      : Removes nil elements from positive extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact!
    if @zsize == nil
      x = @xsize
      y = @ysize
      x -= 1 while row(x - 1).all?{|item| item.nil?} && x > 1
      y -= 1 while column(y - 1).all?{|item| item.nil?} && y > 1
      resize(x, y)
    else
      planes = []
      for z in 0...@zsize
        planes[z] = plane(z).compact!
      end
      planes.delete_at(-1) while planes[-1].all?{|item| item.nil?}
      xmax, ymax = 1, 1
      planes.each{|table|
                  xmax = table.xsize if xmax < table.xsize
                  ymax = table.ysize if ymax < table.ysize
                  }
      resize(xmax, ymax, planes.size)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : Plane
  #   Info      : On a 3D table returns the 2D plane at z value
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical z
  #-------------------------------------------------------------------------
  def plane(z)
    return if @ysize == 1 || @zsize == 1 || z.nil? || z >= @zsize
    plane = Object_Table.new(@xsize, @ysize)
    for x in 0...@xsize
      for y in 0...@ysize
        plane[x, y] = @data[x][y][z]
      end
    end
    return plane
  end
  #-------------------------------------------------------------------------
  # * Name      : Column
  #   Info      : On a 3D or 2D table returns the array at y and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical y and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def column(x, z = nil)
    column = []
    if z.nil?
      for y in 0...@ysize
        column[y] = @data[x][y]
      end
    else
      for y in 0...@ysize
        column[y] = @data[x][y][z]
      end
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Row
  #   Info      : On a 3D or 2D table returns the array at x and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical x and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def row(y, z = nil)
    row = []
    if z.nil?
      for x in 0...@xsize
        row[x] = @data[x][y]
      end
    else
      for x in 0...@xsize
        row[x] = @data[x][y][z]
      end
    end
  end
end
 
some usefull methods for arrays:
I've send them to trickster yesterday night...
So just in case
Code:
class Array
  # rotate  n item(s) to the left ( first becomes last) as a new array
  def rotate_l(n=1)
    a = self.clone
    n.times{a.push(a.shift)}
    return a
  end
  # rotate  n item(s) to the right ( last becomes first) as a new array
  def rotate_r(n=1)
    a = self.clone
    n.times{a.unshift(a.pop)}
    return a
  end
  # rotate n item(s) to the left
  def rotate_l!(n=1)
    n.times{self.push(self.shift)}
    return self
  end
  # rotate n item(s) to the right
  def rotate_r!(n=1)
    n.times{self.unshift(self.pop)}
    return self
  end
end
 
        Here is my first contribution to the Rmxp community, hopefully this gets added to the MCL!
(As if you couldn't tell this goes in the class String section)

Code:
  #-------------------------------------------------------------------------
  # * Name       : Check Prefix
  #   Info       : Checks a String for specified Prefix
  #   Author     : Malucifer
  #   Call Info  : String
  #-------------------------------------------------------------------------
  def starts_with?(string)
     self.index( string ) == 0
  end

  #-------------------------------------------------------------------------
  # * Name       : Check Suffix
  #   Info       : Checks a String for specified Suffix
  #   Author     : Malucifer
  #   Call Info  : String
  #-------------------------------------------------------------------------
  def ends_with?(string)
     self.rindex( string ) == self.length - str.length
  end

I hope this helps somebody....
 

khmp

Sponsor

I don't know if work on this is discontinued or no longer supported but while helping someone out I discovered two tiny bugs that deal with variable misnaming.

Code:
  module Point_Slope
    #------------------------------------------------------------------------
    # * Generate Curve
    #
    #   Args : min_level, max_level, start value, inflation
    #------------------------------------------------------------------------
    def self.generate_curve(min_l, max_level, start_value, inflation)
      # Creates Table
      table = {}
      # Fills Table
      for level in min_l..max_l
        table[level] = start_value + inflation * level
      end
      # Return Table
      return table
    end
  end

Code:
  module Point_Slope
    #------------------------------------------------------------------------
    # * Generate Curve
    #
    #   Args : min_l, max_l, start value, inflation
    #------------------------------------------------------------------------
    def self.generate_curve(min_l, max_l, start_value, inflation)
      # Creates Table
      table = {}
      # Fills Table
      for level in min_l..max_l
        table[level] = start_value + inflation * level
      end
      # Return Table
      return table
    end
  end

Code:
module Curve_Generator
  #-------------------------------------------------------------------------
  # * Save Table
  #-------------------------------------------------------------------------
  def self.save_table(type, args, table)
    # Collects Saved Tables
    tables = self.load_tables
    # Creates Hash of Type (If non present)
    tables[type] = {} unless tables.has_key?(type)
    # Saves Table Data
    tables[type][args] = curve
    # Resaves Tables to File
    save_data(tables, 'Data/Curve Generator.rxdata')    
  end
end

Code:
module Curve_Generator
  #-------------------------------------------------------------------------
  # * Save Table
  #-------------------------------------------------------------------------
  def self.save_table(type, args, table)
    # Collects Saved Tables
    tables = self.load_tables
    # Creates Hash of Type (If non present)
    tables[type] = {} unless tables.has_key?(type)
    # Saves Table Data
    tables[type][args] = table
    # Resaves Tables to File
    save_data(tables, 'Data/Curve Generator.rxdata')    
  end
end
 
The MACL has been updated to version 2.3!


Some of you may be asking, what happened to 2.2? Well many parts of the 2.2 version have been leeked around and about. To avoid any confusion, this is version 2.3. Any old versions of the MACL may be removed completely. We will probably be not using the RSC require method, simply because its a headache for people to get to use. So from here on out, you get one big script (over 16000 lines, go us!).


Let me know if I made any mistakes, as I haven't had a lot of time to review this yet.
 
That's a nice update. I'm massively using the MACL in my FF6 SDK.
I have a suggestion, why don't you add your Bitmap sqr_rotate_90 method to it? It would be a nice addition along with the Bitmap flipping methods.

Also, I found a class_defined? method not long ago if you are interested.
Code:
#============================================================================== 
# ** Kernel     
#==============================================================================

module Kernel
  #-------------------------------------------------------------------------
  # * Name      : Class Defined?
  #   Info      : Check if a specific class has been defined
  #   Author    : David Garamond <lists@zara.6.isreserved.com>
  #   Call Info : One Argument
  #               Class name : String representing the class name
  #-------------------------------------------------------------------------
  def class_defined?(classname) 
    m = Class 
    classname.split("::").each { |c| 
      m.constants.include?(c) or return false 
      m = m.const_get c 
    } 
    return true 
  end
end
 
Thanks. From here on out it will be month updates. I left the post in this thread with anything I am unsure if its already in there. I am going to try to include everything in this thread in the next update, or any other useful methods that pop up.

Code:
#==============================================================================
# ** Object
#==============================================================================

class Object
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  @@subclasses = {}
  #-------------------------------------------------------------------------
  # * Name      : Subclasses
  #   Info      : Gets array of subclasses for class
  #   Author    : SephirothSpawn
  #   Call Info : NA
  #-------------------------------------------------------------------------
  def self.subclasses
    return @@subclasses.has_key?(self) ? @@subclasses[self] : []
  end
  #-------------------------------------------------------------------------
  # * Name      : Add Subclass
  #   Info      : Adds subclass to parent class list
  #   Author    : SephirothSpawn
  #   Call Info : Superclass name & Subclass name
  #-------------------------------------------------------------------------
  def self.add_subclass(superclass, subclass)
    @@subclasses[superclass] = []  unless @@subclasses.has_key?(superclass)
    @@subclasses[superclass] << subclass unless @@subclasses[self].include?(subclass)
  end
  #-------------------------------------------------------------------------
  # * Object.inherited
  #-------------------------------------------------------------------------
  def self.inherited(subclass)
    self.add_subclass(subclass.superclass, subclass)
  end
end


class Game_Character
  for turn in ['turn_down', 'turn_left', 'turn_right', 'turn_up']
    s  = "alias_method :seph_macl_turnbase_#{turn}, :#{turn};"
    s += "def #{turn};"
    s += "  turn_base;"
    s += "  seph_macl_turnbase_#{turn};"
    s += "end;"
    eval s
  end
  def turn_base
  end
end
 
I have a little problem with the pathfinding sintax:

I use this: $game_map.events[1].run_path(10, 10)

and I get this:

Wrong number of arguments(2 for 0).
 
But i have a question, this Pathfinding is used to move the player or the event to a Position?, because I cant do that.

Can you explain a little better this pathfinding?
 
Yes, it works for any Game_Character object. It moves them to the dest x, y position or should...

*runs off*

(I am actually going to do some research and possibly improve this for the next update. I was working with pathfinding nodes, but that was before xmas break.)
 

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