Arrays and hashes are similar. The biggest difference between these two objects is that the array is 'index based' and the hash is 'key based'
An index is always a number. A key can be a number or a string. It can probably be more but I'm not sure.
here's an example of an array:
Friends = [ "Mike", "Stef", "Jim" ]
Friends[2] # => "Jim"
Friends[0] # => "Mike"
Friends[1] # => "Stef"
Expand to see the code.
here's an example of an hash:
Age = { "Mike" => 20, "Stef> => 18, "Jim" => 16 }
Age["Mike"] # => 20
Age["Stef"] # => 18
Age["Jim"] # => 16
Expand to see the code.
Note the difference; in the hash, you must specify the key and its value like that: Hash = { key => value }
It's also possible with an array but the method differs a bit; Array[index] = value
Alias is a Ruby keyword used to create a new name for an existing method. One of the greatest advantages of the alias is that you can modify an existing method without having to overwrite it. Usually, overridden methods are the source of compatibility issues, bugs, etc.
I'll give you an example. Here's the original element_set method in Game_Actor:
#--------------------------------------------------------------------------
# * Get Normal Attack Element
#--------------------------------------------------------------------------
def element_set
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.element_set : []
end
Expand to see the code.
And Here's what it would look like if I overwrite it.
#--------------------------------------------------------------------------
# * Get Normal Attack Element
#--------------------------------------------------------------------------
def element_set
new_elements = []
for state_id in @states
new_elements.push(Elemental_Attack[state_id])
end
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.element_set + new_elements: [] + new_elements
end
Expand to see the code.
In your case, this method would probably work just fine, unless you have a bunch of custom scripts.
Now here's what it would look like if I use an alias.
Quote:
alias new_element_set element_set
#--------------------------------------------------------------------------
# * Get Normal Attack Element
#--------------------------------------------------------------------------
def element_set
# Create new elements array
new_elements = []
for state_id in @states
# Add elements to the array
new_elements.push(Elemental_Attack[state_id])
end
# Combine the last method with the element array
return new_element_set + new_elements
end
The name in green is the new method name and the name in blue is the original method name.
The variable in red is our array which will contain every extra element ID.
In the last line, the aliased original method (in green) is executed and we are adding our array of new elements.