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.
It was []=, and it defines the operator [] for use with objects of that type. It's usually used for array wrapper data types.
Look at Game_Actors:
Code:
class Game_Actors
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Actor
# actor_id : actor ID
#--------------------------------------------------------------------------
def [](actor_id)
if actor_id > 999 or $data_actors[actor_id] == nil
return nil
end
if @data[actor_id] == nil
@data[actor_id] = Game_Actor.new(actor_id)
end
return @data[actor_id]
end
end
$game_actors is not an array, but you can use $game_actors to access the actors at the various indices just like an array thanks to the #[] method.
[]= would allow you to assign the object to an array. For example, if we were adding that method to a class:
Code:
class Foo
def initialize
@data = []
end
def []=(somearray)
@data = somearray
end
def [](i)
return @data[i]
end
end
This topic has been resolved. If Aran or any other users have any questions or further problems regarding this topic, please create a new thread about them.